can't set zoom level on MKMapView

南楼画角 提交于 2020-01-05 08:04:19

问题


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?


回答1:


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



回答2:


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;



回答3:


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

Otherwise use Anna's solution



来源:https://stackoverflow.com/questions/20661899/cant-set-zoom-level-on-mkmapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!