MKMapView: Follow Current Location with current zoom level
I have a method that works to move the the map so that it follows the current user location. This works fine, but currently the zoom scale doesn't work how I want. I would like the user to be able to zoom out or zoom in on the map how they want and still have it follow the current location at that NEW zoom scale that the user just set on the map.
I tried to do the following but it doesn't work well:
/**
* Centers the map on the current location
*
* @version $Revision: 0.1
*/
- (void)centerMapOnLocation:(CLLocation *)location {
// Make a region using our current zoo开发者_StackOverflow社区m level
CLLocationDistance latitude = mapView.region.span.latitudeDelta*100;
CLLocationDistance longitude = mapView.region.span.longitudeDelta*100;
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(location.coordinate, latitude, longitude);
[mapView setRegion:region animated:YES];
}//end
MKMapView Zoom and Region describes how to get the current view window.
When you're creating the new MKCoordinateRegion
to set the new view to, use the constructor that allows you to specify the size:
UIKIT_STATIC_INLINE MKCoordinateRegion MKCoordinateRegionMake(
CLLocationCoordinate2D centerCoordinate,
MKCoordinateSpan span
);
You'll want to pass in the span
from the current region and the centerCoordinate
from the user location, which I'll take it you already got.
精彩评论