Geolocation showing old/outdated data

You must Login before you can answer or comment on any questions.

Hello,

I'm trying to get devices position and Ti.GeoLocation.getCurrentPosition() is returning old data, judging by the timestamp and location it's providing. I ran GoogleMaps yesterday and it showed my position then, but now when I run my own application and try to get current position, it's still returning that old position from GoogleMaps, which is about 80km away from my current location. So...help? :)

Oh and, the application must work with both, GPS and network geolocation, depending on which is available.

Code:

function GetLocation() {
    if (Ti.Geolocation.locationServicesEnabled) {
            Ti.Geolocation.purpose = 'Get Current Location';
            Ti.Geolocation.preferredProvider = Ti.Geolocation.PROVIDER_NETWORK;
            Ti.Geolocation.accuracy = Ti.Geolocation.ACCURACY_LOW;
            Ti.Geolocation.getCurrentPosition(function(e) {
            if (e.error) {
                    alert('Error: ' + e.error);
            } else {
                    alert(e.coords);
            }
            });
    } else {
            alert('Please enable location services');
    }
        return "";
    }

1 Answer

Accepted Answer

getCurrentLocation gets a "cached" value of the coordinates. It doesn't start the gps on the device so is not taking the real current position. You will have to use the location event for this.

— answered 7 months ago by Dan Tamas
answer permalink
3 Comments
  • Okay, thanks. But is there a way where I can manually request location update?

    — commented 7 months ago by Tomaž Lovrec

  • Do you have any code that works for this?

    — commented 3 months ago by Richard Harrysson

  • @Tomaz You can try to add and remove the event listener so the device doesn't stay all the time with the GPS on, but this way you will have the delay on each start.

    @Richard - what code do you ask for? If is the location event you can find it easily in the KS:

    https://github.com/appcelerator/KitchenSink/blob/master/Resources/ui/common/phone/geolocation.js#L461

    — commented 3 months ago by Dan Tamas

Your Answer

Think you can help? Login to answer this question!