So I faced the same problem. What I was getting was an error like this: “{}”.
I looked at the source code and was amazed. No wonder it does not work, because there is no code implementing it! Just permission request. Maybe I am missing something… but the thing is: it does not work.
I was experiencing similar problems on Android with the geolocation plugin not returning a success or error response on Android if I disabled location services.
I noted the following section from the github page README:
Android Quirks
If Geolocation service is turned off the onError callback is invoked after timeout interval (if specified). If timeout parameter is not specified then no callback is called.
Adding a timeout to the call resolved the issue for me.
sir in my case getCurrentPosition are not fire initially and i have trigger function only inside ionViewDidLoad() function why function not fire initially …
For me I found out the problem was that the GPS was simply disabled on the device, after I activated the location services everything worked using the following code:
Getting the current position during start up runs the risk of being rejected on start up in browsers.
[Violation] Only request geolocation information in response to a user gesture.
There’s a recommendation from Google not to load geolocation on page load:
Users are mistrustful of or confused by pages that automatically request their location on page load. Rather than automatically requesting a user’s location on page load, tie the request to a user’s gesture, such as a tapping a “Find Stores Near Me” button. Make sure that the gesture clearly and explicitly expresses the need for the user’s location.
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.