iphone - MKMapView's user location is wrong on startup or resume -


when start application fresh, or resume after long time, mkmapview's notion of userlocation wrong , shows me in middle of sea.

i using following code:

self.mapview.centercoordinate = self.mapview.userlocation.location.coordinate; [mapview setcentercoordinate:self.mapview.userlocation.location.coordinate zoomlevel:zoom_level animated:yes]; 

happens after lengthy resume of app or brand new start....

that's expected behavior : user location isn't tracked iphone using gps (it consume battery). map displayed, mkmapview instance shows last 'best' user position knows , then, improves accuracy activating tracking (this seamless process, don't have care it) .

you can monitor when mkmapview updates user location on map implementing mkmapviewdelegate protocol. implement :

- (void)mapview:(mkmapview *)mapview didupdateuserlocation:(mkuserlocation *)userlocation      {     cllocationaccuracy accuracy = userlocation.location.horizontalaccuracy;     if (accuracy ......) {     }  } 

(more info apple documentation here )

the code above in example checks accuracy of position being displayed mapview , reacts accordingly.

[edit]
if showing user location in middle of sea @ first bother you, can hide user location until location accurate/fresh enough.
so, set showsuserlocation property of mkmapview no @ first until accurate enough location (thanks previous delegate callback) , set yes.
doing you, avoid displaying location not accurate or old diplayed (there timestamp property in cllocation check wether it's old location or not)

n.b:you don't have create cllocationmanager instance on side, mkmapview creates 1 internally , publish locations receives via delegate selector.


Comments

Popular posts from this blog

python - Scipy curvefit RuntimeError:Optimal parameters not found: Number of calls to function has reached maxfev = 1000 -

c# - How to add a new treeview at the selected node? -

java - netbeans "Please wait - classpath scanning in progress..." -