Geolocation Issues

I am trying to use Geolocation but I get the below error
TypeError: Object(…) is not a function
at Geolocation.getCurrentPosition

Ionic Version 3.20.0
cordova-plugin-geolocation 4.0.1 “Geolocation”

my code

import { Geolocation } from ‘@ionic-native/geolocation/ngx’;
this.geolocation.getCurrentPosition().then((resp) => { = resp.coords.latitude;
this.longt =resp.coords.longitude;
}).catch((error) => {
console.log(‘Error getting location’, error);

any idea what I can do

Thank you

1 Like

if you found solution tell me please , i have the same problem

If you wants please follow and understand then apply given coding.

platform.ready().then(() => {
this.geolocation.getCurrentPosition({enableHighAccuracy: true}).then((resp) => { resp.coords.latitude;
this.lng= resp.coords.longitude;
}).catch((error) => {
console.log(‘Error getting location’, error);
Then converting lat and lng for given coding.
this.platform.ready().then(() => {
let options: NativeGeocoderOptions = {
useLocale: false,
maxResults: 5
.then((result: NativeGeocoderReverseResult) =>{
console.log(JSON.stringify(result[0])); = result[0].subLocality +","+ result[0].locality +","+
result[0].subAdministrativeArea +","+ result[0].administrativeArea +","+
result[0].postalCode +","+ result[0].countryName;
}).catch((error: any) => console.log(error));
Please properly understand and then apply above coding for geolocation.
Thank you!
This is ionic 3 and Angular Js 5.

that not work for me

Sorry for the delay response, Please use two plugins 1.Geo coder 2.Geolocation.
1 link is
2 link is
install two plugins then use above coding properly it will working…
Thank you! If you got a solution ,click the solution but bcoz users find what is solution.

Hi! Im facing the same issue. I’ve already made some changes like update rxjs to 6.0 version, put /ngx in native-geocoder and Geolocation package imports. But nothing worked.

@karthikaivel I’ve also tried your code above but it throws the same error.

Moreover, I tested only the code for getCurrentPosition in platform.ready, without to call reverseGeocoding function, but I still get the first error

“Uncaught (in promise): TypeError: Object(…) is not a function
TypeError: Object(…) is not a function”

Found the fix. At least the above worked for me.

I checked my depedencies in package.json file. Not all of my ionic-native plugins were in the same version. (5.2.0), so I update each of them with the command

npm install --save @ionic-native@(plugin_name)@latest

Also I update rxjs and added rxjs-compat with the above command

npm i rxjs@^6.0 rxjs-compat

Finally, geolocation must be imported with the above way

import { Geolocation } from '@ionic-native/geolocation/ngx';

Hope it helps. getCurrentPosition doesn’t throw any error

1 Like

If working with ionic 3, use these to install the geolocation plugin:

ionic cordova plugin add cordova-plugin-geolocation
npm install --save @ionic-native/geolocation@4

i tried to arrange the code, because I think the problem in the code

     constructor(public navCtrl: NavController,private geolocation: Geolocation) { 

      navigator.geolocation.getCurrentPosition(this.onSuccess, this.onError);
          onError(error) {
        alert('code: '    + error.code    + '\n' +
          'message: ' + error.message + '\n');
         onSuccess(position) {
         let element = document.getElementById('map');
         element.innerHTML = 'Latitude: '  + position.coords.latitude      + '<br />' +
                      'Longitude: ' + position.coords.longitude     + '<br />' +
                      '<hr />'      + element.innerHTML;

also, you can see the tutorial here

Sorry for that,But properly work for me.
Thank you!

“npm install --save @ionic-native/geolocation@4” also worked for me.