ios - Center MKMapView on userLocation (initially) - only works on iPhone 4? -


i implemented following mkmapview method, runs after annotations added. have mkmapview map (parishmap) set "shows user location" in interface builder, , upon loading mapview, blue dot appears within second or on mapview.

here's code have in map view controller implementation:

// center map on user location (initially) - (void)mapview:(mkmapview *)mapview didaddannotationviews:(nsarray *)views {     for(mkannotationview *annotationview in views) {         if(annotationview.annotation == parishmap.userlocation) {             mkcoordinateregion region;             mkcoordinatespan span;              span.latitudedelta=0.03;             span.longitudedelta=0.03;              cllocationcoordinate2d location=parishmap.userlocation.coordinate;              location = parishmap.userlocation.location.coordinate;              region.span=span;             region.center=location;              [parishmap setregion:region animated:true];             [parishmap regionthatfits:region];         }     } } 

when open mapview on iphone 4, mapview (and immediately) moves center on userlocation dot. however, when open mapview on iphone 3gs or ipod touch (2010), doesn't center on userlocation, stays @ default zoom/region set map view.

any ideas why code won't work non-iphone 4 devices (they're running 4.2.x latest ios)?

this issue amount of time takes gps lock position on these different devices.

i'd recommend using cllocationmanager , delegate methods center map.

you can start updating location creating instance of cllocationmanager, setting delegate property self , implementing:

- (void)locationmanager:(cllocationmanager *)manager didupdatetolocation:(cllocation *)newlocation fromlocation:(cllocation *)oldlocation

where can center map accordingly based on latest location update.


Comments

Popular posts from this blog

Javascript line number mapping -

linux - Mailx and Gmail nss config dir -

c# - Is it possible to remove an existing registration from Autofac container builder? -