I'm using map kit and showing user's location using "showsUserLocation" I"m using following code to zoom to user's location, but not zooming. Its zooming to some location in Africa, though the user location on map is showing correct.
MKCoordinateRegion newRegion;
MKUserLocation* usrLocation = mapView.userLocation;
newRegion.center.latitude = usrLocation.location.coordinate.latitude;
newRegion.center.longitude = usrLocation.location.coordinate.longitude;
newRegion.span.latitudeDelta = 20.0;
newRegion.span.longitudeDelta = 28.0;
[self.mapView setRegion:newRegion animated:YES];
Why is user's location correctly showing and not zooming properly. Can some one correct me please?
mapView.userLocation is set to a location off the coast of Africa (0,0) when first instantiated. As a result, I do something like the following, which causes the zoom to occur when the annotation appears. Of course, this is just an example:
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views {
for(MKAnnotationView *annotationView in views) {
if(annotationView.annotation == mv.userLocation) {
MKCoordinateRegion region;
MKCoordinateSpan span;
span.latitudeDelta=0.1;
span.longitudeDelta=0.1;
CLLocationCoordinate2D location=mv.userLocation.coordinate;
region.span=span;
region.center=location;
[mv setRegion:region animated:TRUE];
[mv regionThatFits:region];
}
}
}
you can try:
mapView.userTrackingMode=YES;
mapView.userTrackingMode=NO;
UserTrackingMode will zoom to user Location.
Have you verified that the location returned by mapView.userLocation
isn't at 0, 0?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With