Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

getCurrentPosition not updating

Hi everyone. I have to get the current location of the user in my mobile app.

It works fine. But if close the app, go somewhere else et restart the app, I'm still located in the previous place. I have to set the current position in the Plans app from iPhone for exemple and then in my own map I'm right located.

Does someone know where can be the problem and how can I fix it?

Here's my code

var lat;
var long;

//set the mapview with the current location
var mapview = Titanium.Map.createView({
    mapType: Titanium.Map.STANDARD_TYPE,
    animate:true,
    region: {latitude:lat, longitude:long, latitudeDelta:0.005, longitudeDelta:0.005},
    regionFit:true,
    userLocation:false,
    visible: false,
    bottom: 50
});

function getLocation(){
//Get the current position and set it to the mapview
Titanium.Geolocation.getCurrentPosition(function(e){
        var region={
            latitude: e.coords.latitude,
            longitude: e.coords.longitude,
            animate:true,
            latitudeDelta:0.01,
            longitudeDelta:0.01
        };
        mapview.setLocation(region);
});
}

win.add(mapview);

win.addEventListener('open',function(){
    listView.setData(inputData);
    getLocation();
});

Thx in advance

— asked July 1st 2010 by Brice Torriani
  • iphone
  • location
  • map
0 Comments

4 Answers

  • Okay I haven't said anything. It's because was was on wifi connection instead of 3g. Accuracy is not very good, but anyway it works.

    — answered July 1st 2010 by Brice Torriani
    permalink
    0 Comments
  • The accuracy used is configurable.
    Something along the lines of:

    Titanium.Geolocation.accuracy = Titanium.Geolocation.ACCURACY_NEAREST_TEN_METERS;
    

    You can ofc use any of the accuracy constants.

    — answered July 1st 2010 by David Ashwood
    permalink
    1 Comment
    • tbh - it's not well documented.

      — commented July 1st 2010 by David Ashwood
  • Do you think it's better than ACCURACY_BEST (that's what I'm actually using)?

    — answered July 1st 2010 by Brice Torriani
    permalink
    1 Comment
    • Nope - it was just an example :)

      — commented July 1st 2010 by David Ashwood
  • I have seen this issue also - on subsequent requests, the location is updated properly. Still trying to triangulate the source of the trouble, but you can monitor the user's position for a few seconds to grab the data you need - check around line 313.

    — answered July 1st 2010 by Kevin Whinnery
    permalink
    2 Comments
    • Did this ever get fixed, Kevin? I'm having a similar problem. It is almost as if the LAT/LONG returned from getCurrentPosition is being cached.

      — commented March 8th 2011 by Bart Lewis
    • Did someone get this work done ?? I am still having the same problem. Is there any way to remove cached location from device ?

      — commented May 9th 2014 by Muhammad Burhan
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.