# Ionic Native Gelocation not working

**URL:** <https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808>\
**Category:** Ionic Native\
**Created:** [June 26, 2017, 9:46am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808 "2017-06-26T09:46:33Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![varunvarde2007](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@varunvarde2007](https://forum.ionicframework.com/u/varunvarde2007)\
**Post date:** [June 26, 2017, 9:46am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/1 "2017-06-26T09:46:33Z")

</div>

Hi,

Somehow the geolocation plugin is not working on one of the app i am building.

I have installed the Geolocation plugin using the following commands

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

```

The plugins are installled correctly.

Following is the code that i am running in Platform.ready() in app.component.ts

```auto
let geoOptions: GeolocationOptions = {
        enableHighAccuracy:true,
        timeout:500000,
        maximumAge:10,
      };

      this.geolocation.getCurrentPosition(geoOptions).then((data: Geoposition) => {
        console.log("Success", data);
      }, (error: PositionError) => {
        console.log("Error", error);
      });

```

The Success callback is never called. I have verified the location access is enabled on the device. Also, in the error call back the error is blank.

What is it i am doing wrong here?

---

<div class="post-metadata">

**Author:** ![Sujan12](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sujan12/32/108395_2.png) [@Sujan12](https://forum.ionicframework.com/u/Sujan12)\
**Post date:** [June 26, 2017, 9:52am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/2 "2017-06-26T09:52:29Z")

</div>

Did you also do Step 2 of the Installation instructions?  
[https://ionicframework.com/docs/native/geolocation/](https://ionicframework.com/docs/native/geolocation/)

---

<div class="post-metadata">

**Author:** ![varunvarde2007](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@varunvarde2007](https://forum.ionicframework.com/u/varunvarde2007)\
**Post date:** [June 26, 2017, 10:17am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/3 "2017-06-26T10:17:26Z")

</div>

@Sujan12  
Yes forgot to mention i did add it under app.modules.ts  
`import {Geolocation} from "@ionic-native/geolocation";`

```auto
providers: [StatusBar,
   SplashScreen,
   {provide: ErrorHandler, useClass: IonicErrorHandler},
   RequestManagerProvider,
   UserProvider,
   CategoriesProvider,
   PostsProvider,
   Geolocation]

```

Still the same issue.

---

<div class="post-metadata">

**Author:** ![kgaspar](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/kgaspar/32/108738_2.png) [@kgaspar](https://forum.ionicframework.com/u/kgaspar)\
**Post date:** [June 26, 2017, 12:03pm UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/4 "2017-06-26T12:03:41Z")

</div>

Have you granted location access to your app?

---

<div class="post-metadata">

**Author:** ![ramon](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/ramon/32/75852_2.png) [@ramon](https://forum.ionicframework.com/u/ramon)\
**Post date:** [June 28, 2017, 8:22am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/5 "2017-06-28T08:22:08Z")

</div>

Yes. I’m facing similar issue, but only in some Android devices.

To get user location I’m using the following provider:

```auto
import {Injectable} from '@angular/core';
import {Geolocation, GeolocationOptions} from "@ionic-native/geolocation";
import {Storage} from "@ionic/storage";

import {Position} from "../../models/position.model";

@Injectable()
export class GeolocationProvider {

    private position: Position = {
        latitud: null,
        longitud: null
    };

    constructor(private geolocation: Geolocation, private storage: Storage) {}

    public getUserCurrentPosition(): Promise<Position> {
        console.log('[GeoProvider] getUserCurrentPosition launched...');

        return new Promise((resolve, reject) => {

            let geolocationOptions: GeolocationOptions = {
                enableHighAccuracy: true,
                timeout: 2500,
                maximumAge: 600000 // 10 minuts
            };

            this.geolocation.getCurrentPosition(geolocationOptions).then(
                (position) => {
                    console.log('[GeoProvider] getCurrentPosition success: ', position.coords.latitude, position.coords.longitude);
                    this.position.latitud = position.coords.latitude;
                    this.position.longitud = position.coords.longitude;
                    this.savePositionLocally();
                    resolve(this.position);
                },
                (err) => {
                    console.error('[GeoProvider] getCurrentPosition error: ', err);
                    if (this.position.latitud != null && this.position.longitud != null) {
                        resolve(this.position);
                    } else {
                        this.getPositionLocally().then(
                            (position: Position) => {
                                if(position) {
                                    console.log('[GeoProvider] getPositionLocally success.', position);
                                    this.position = position;
                                } else {
                                    console.log('[GeoProvider] getPositionLocally success. No older position.', position);
                                    reject();
                                }
                            },
                            () => {
                                console.warn('[GeoProvider] getPositionLocally error.');
                                reject();
                            }
                        );
                    }
                }
            );

        });
    }

    private savePositionLocally(): void {
        this.storage.set("user.position", this.position).then(
            () => {
                console.log('[GeoProvider] Save position success.');
            },
            () => {
                console.warn('[GeoProvider] Save position error.');
            }
        );
    }

    private getPositionLocally(): Promise<any> {
        return this.storage.get("user.position");
    }

}

```

If I run my APP to an Moto G3 it works. Also in a Sony Xperia T3 and 1+One.  
But when I run the application to a BQ Aquaris M10 I allways get timeout error.

Sorry for my english. It’s not my native language.

---

<div class="post-metadata">

**Author:** ![varunvarde2007](https://avatars.discourse-cdn.com/v4/letter/v/9f8e36/32.png) [@varunvarde2007](https://forum.ionicframework.com/u/varunvarde2007)\
**Post date:** [July 6, 2017, 10:38am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/6 "2017-07-06T10:38:16Z")

</div>

After a long trial and error. I removed the platorm and the plugin and re added it. It worked, don’t know what exactly happened

---

<div class="post-metadata">

**Author:** ![juliosampaio](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/juliosampaio/32/81437_2.png) [@juliosampaio](https://forum.ionicframework.com/u/juliosampaio)\
**Post date:** [August 6, 2017, 3:42pm UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/7 "2017-08-06T15:42:43Z")

</div>

I did exactly the same steps as you and it still not working ☹ any other tips guys? this issue is driving me crazy 😅

---

<div class="post-metadata">

**Author:** ![RomnEmpire](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/romnempire/32/124028_2.png) [@RomnEmpire](https://forum.ionicframework.com/u/RomnEmpire)\
**Post date:** [April 28, 2019, 8:45am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/8 "2019-04-28T08:45:27Z")

</div>

Hi,  
i have also got same problem but in my case not received error callback or nor success callback,i don’t understand what the problem is that,i have also tried remove the platform and again add platform but not working i am using android 6.4 version.bro do you know any another way to fix?

---

<div class="post-metadata">

**Author:** ![sebafra](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/sebafra/32/113464_2.png) [@sebafra](https://forum.ionicframework.com/u/sebafra)\
**Post date:** [September 2, 2019, 3:36am UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/9 "2019-09-02T03:36:49Z")

</div>

Hi, did you find any solution to this?

---

<div class="post-metadata">

**Author:** ![dnsmenjivar](https://avatars.discourse-cdn.com/v4/letter/d/8c91f0/32.png) [@dnsmenjivar](https://forum.ionicframework.com/u/dnsmenjivar)\
**Post date:** [June 4, 2020, 8:29pm UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/10 "2020-06-04T20:29:29Z")

</div>

NW just have to include this line in your code:  
this.geolocation.getCurrentPosition({ ‘enableHighAccuracy’: true }).then(geo=\>{  
[//geo.coords.latitude](https://geo.coords.latitude)  
});

Please don’t forget to include ‘enableHighAccuracy’ with: ‘’

It was a very pleasure

---

<div class="post-metadata">

**Author:** ![davidtatenda](https://avatars.discourse-cdn.com/v4/letter/d/b4bc9f/32.png) [@davidtatenda](https://forum.ionicframework.com/u/davidtatenda)\
**Post date:** [July 7, 2020, 7:26pm UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/11 "2020-07-07T19:26:24Z")

</div>

For all those facing the issue where the function below does not work on Android device.

`this.geolocation.getCurrentPosition()`

I fixed the issue after a day of scratching my head and Googling…  
Just switch on “ **Location Services** ” on your android device.  
Accepting location services when calling the function does not switch ON the location services.

---

<div class="post-metadata">

**Author:** ![mhartington](https://sea1.discourse-cdn.com/ionicframework/user_avatar/forum.ionicframework.com/mhartington/32/137757_2.png) [@mhartington](https://forum.ionicframework.com/u/mhartington)\
**Post date:** [July 19, 2021, 8:54pm UTC](https://forum.ionicframework.com/t/ionic-native-gelocation-not-working/95808/12 "2021-07-19T20:54:25Z")

</div>

Closed on July 19, 2021, 8:54pm UTC


