ngCordova with geolocation not working

I had this issue once, what solved for me was using ‘navigator’ instead of $cordovaGeolocation, like so:

navigator.geolocation.getCurrentPosition()

I don’t really know why it works like this for me, but it does… I hope it helps :wink:

@brunodb3 Using navigator means not using ngCordova, and it’s difference kind of implementation.
Is ngCordova bugy or there is something else to it?

If nothing works, I will get to use navigator. Might be a good idea to dumb ngCordova

If i use ngCordova, i doesn’t work either, so i am using navigator. I don’t really know why it doesn’t work though…

i heard crosswalk is “bugging” some cordova plugins, you are using it? if yes, already tried without it?

Yes, i’m using CrossWalk, but even without it, ngCordova doesn’t work…

This is quite poor! I will have to change my implementation to use navigator, I been doing this for the past day and it is not fun.

But I noticed that it does give output after waiting for some time uisng ngCordova, only in one instance. In the my homeCtrl for reverse geocoding, but it doesn’t work on displaying markers on the google map at all.
But that also goes for navigator.geolocation it didn’t show any results in the device.

Is there any stable framework api for this that I can use or some way around it? I am not using crosswalk btw. But I got other plugings and dependencies on which might effect it

Regarding the Nexus not working but the browser does, you need to setup the Chrome USB debugging so that you can see the state of the objects.

By the looks of it you are not waiting for your platform to be ready. The first thing you are doing in your controller is trying to get a handle on your google.maps. This doesn’t work on my Nexus 5 because it takes a little longer to fire up the service.

I initially used the ionic.Platform.ready() function at the bottom of my controller but with the recent view caching improvements I have found that using this works better because you know the page is loaded and ready to use:

var geo = {};
$scope.$on('$ionicView.enter', function(event, data) {
    geo = google.maps.Geocoder();
    // carry on with other processing
})

Since Cordova 4.0 you need the Cordova Whitelist plugin to be able to access remote resources like Goole Maps.

Read more about it here:

hi my friend i have an issue with that , the geolocation ng cordovas plugin works in my browser but not in my device i already install the whitelist plugin and i put the security tag in my index.html but it still doesnt work. i dont know what to do google maps dont work, do i have to downgrade de cordova?
what would be your recomendation. thanks

Sounds like you might’ve come across an issue that I’m currently having :slight_smile: see if any of their suggestions work: Ionic Geolocation plugin working on browser but not iOS and Android Emulators

thanks my friend , ive seen of all that suggeston and nothing… :tired_face:. i have
the same issue that u have even the same error code POSITION_UNAVAILABLE.
did you solve the problem?

2016-08-05 18:37 GMT-05:00 Jourdan Bul-lalayao <
ionicframework@discoursemail.com>:

Hey man; nope I was never able to fix it, however, if it helps, the issue does not happen when viewing your app on an iOS Device (through Ionic View or your app itself). Meaning, Geolocation doesn’t work on the iOS Simulator (for the both of us at least), but you can still test your Geolocation feature on your own iOS device without any issues!

Hopefully though, if it is issue with Ionic or Geolocation themselves not working in the iOS Simulator, it’s fixed in an upcoming release >.<.

did you solve that problem? i have the same issue , it works on my browser but not on my note 5 . in my old android device it works!. thats weird!

I had the same problem where it was working in browser but on my devices it was not. I found that my problem was that the cordova-plugin-geolocation was not installed. I found this when I typed ionic plugins and noticed that it was missing. It’s very strange that there was no error whatsoever, it just gave me that pesky timeout error which was very misleading.

EDIT: I’ve noticed too that in my options I seem to need {…, enableHighAccuracy: true, maximumAge: 0}

ionic plugins add cordova-plugin-geolocation is what solved this for me.

see my answer below, maybe that will help you too. I did not have cordova-plugin-geolocation installed in my plugins

Any Update on this. I am getting blank result in android 5.1.1 but in android 6 it is working fine.

Has anyone found their way around this problem ?

seems to be working fine on android versions 5.x & 4.x ,
I have tested it on a number of android 6.x devices and that is where the problem seems to be happening.

I am using the latest version of google play services 10.1

Got the same issue, geolocation plugin not working on nexus 5x running android 6.0 … It works on other devices running older versions of Android, tried all the suggestions here and more, no luck…anyone found a fix?

When you debug your app in Chrome, you see this warning:

getCurrentPosition() and watchPosition() no longer work on insecure origins. To use this feature, you should consider switching your application to a secure origin, such as HTTPS…

Had the same issue, and solved it by changing the timeout duration from 1’000 to 10’000:

    $cordovaGeolocation.getCurrentPosition({
        timeout: 10000,
        enableHighAccuracy: false
    })