can't set zoom level on MKMapView

2019-07-31 10:22发布

i am adding MKCircleView to the user annotation like so :

- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
if (!_MapCentered) {
    **_circle = [MKCircle circleWithCenterCoordinate:userLocation.coordinate radius:3000];
    [_map_view addOverlay:_circle];** 
    _MapCentered = YES;
    }
}

it will fire once and once the user location has traced, it works well but as you can see the diameter of the circle view is 3000 meters. so now i want the zoom level to fit the CircleView like so :

        MKCoordinateRegion viewRegion = MKCoordinateRegionMakeWithDistance(mapView.userLocation.coordinate, 0.270, 0.270);
    [_map_view setRegion:viewRegion animated:YES];

i have changed the delta degrees to other numbers but nothing is changed. how can i manage this?

3条回答
太酷不给撩
2楼-- · 2019-07-31 10:36

For Google's zoom level i use this category for MKMapView

Otherwise use Anna's solution

查看更多
爷、活的狠高调
3楼-- · 2019-07-31 10:38

The distance parameters in the MKCoordinateRegionMakeWithDistance function are in meters (not degrees).

Also, the meters specify the full width and height so you have to use double the value of the circle's radius.

So it should be:

MKCoordinateRegion viewRegion = 
  MKCoordinateRegionMakeWithDistance
    (mapView.userLocation.coordinate, 6000, 6000);


You could also just set the map view's visibleMapRect to the boundingMapRect of the circle overlay so you don't have to repeat the distance values:

mapView.visibleMapRect = _circle.boundingMapRect;
查看更多
【Aperson】
4楼-- · 2019-07-31 10:43

You need to set your span. so set your span value in longitudeDelta & latitudeDelta

yourRegion.span.longitudeDelta  = 0.004; // set required zoom value 
yourRegion.span.latitudeDelta  = 0.004; // set required zoom value
查看更多
登录 后发表回答