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
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.
-
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.
-
Do you think it's better than ACCURACY_BEST (that's what I'm actually using)?
-
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.