Geolocation service is not working without a hard refresh

Hi,

We are using the following bit of code to fetch the location as part of a service defined as a factory.

getLocation: function() {
var q = $q.defer();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
q.resolve(position);
}, function(error) {
q.reject(error);
},{maximumAge:60000, timeout:10000, enableHighAccuracy:true});
} else {
console.log(‘permission denied’);
}
return q.promise;
}

This is also called by a resolve in a state provider.

.state(‘foo.bar’, {
url: “/check-in”,
views: {
‘menuContent’: {
templateUrl: “check-in.html”,
controller: “CheckinCtrl”
}
},
resolve: {
geo: “Geo”,
location: function(geo){
geo.getLocation().then(function (position) {…}
}
}

When we navigate to the state foo, one of two things happen

a) In the normal navigation, the geolocation service times out and we don’t get any response.
b) On a hard refresh however (ie, hitting the refresh button on the browser), everything works as normal. All the data is loaded as expected.

Can anyone help.

Thanks
Nikhil

Take a look at this sample to see if it helps.

At the bottom right, there is a navigation pointer icon. Click it, the browser asks for your location. You can move around again and then click it again and all works.

In continuation, when I use the
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(function(position) {
console.log(“Inside navigator:”+JSON.stringify(position));
q.resolve(position);

I get a Code 3, timeout. I’ve seen this problem all over when someone uses a cordova/phonegap platform. Does anyone have a probably solution?
Clicking refresh on the browser enables me to retrieve data without the code3 timeout.

Looks like something must have changed in ionic or google maps because now i’m unable to get my location (alert: failed to get latlong) on my mobile phone or your codepen.

That example was working for me on my app, but after some beta updates, now dont works anymore.

Any fresh news on that?

i’m interested too, any news?

navigator.geolocation is something that works one day and is broken 2 days more.
I think that we should go to geolocation by some cordova plugin.

its not broken it just takes time to get a lock the first time , later on it works from cache and is quick . If you clear the cache from phone it has to again get the lock , if gps is not enabled during this time it takes a long time to get the lock.

I have the same problem . I post some pictures with the code and result.

When the app start with GPS on, everything is working, but when starts with GPS off and later GPS is enabled from device settings , the problem occurs. . I am using cache view and i try to reload the view, but it doesn´t work.


Uploading…
Uploading…
Uploading…