相关疑难解决方法(0)

在MapKit中缩小和拟合所有注释的最佳方法是什么

快速了解我的情况.UIMapView加载并显示单个注释(从不多于一个).在菜单栏上,有一个Locate Me按钮,点击查找userLocation并显示为第二个注释.然后我将MapView缩小以适应范围内的那些注释,但我无法找到合适的方法.根据第一个注释相对于用户位置的位置,有时它不会缩小.

例如,如果注释位于用户的西北方向,则会缩小范围.但是如果注释是用户的东南方,它只会缩小到足以让它们被切断,你必须手动缩小一点.这是我正在使用的代码,我在SO上找到的其他一些代码的变体.

        CLLocation *whereIAm = mapView.userLocation.location;

        float lat = whereIAm.coordinate.latitude;
        float lon = whereIAm.coordinate.longitude;


        CLLocationCoordinate2D southWest = {[currentLatitude floatValue], [currentLongitude floatValue]};
        CLLocationCoordinate2D northEast = southWest;

        southWest.latitude = MIN(southWest.latitude, lat);
        southWest.longitude = MIN(southWest.longitude, lon);

        northEast.latitude = MAX(northEast.latitude, lat);
        northEast.longitude = MAX(northEast.longitude, lon);

        CLLocation *locSouthWest = [[CLLocation alloc] initWithLatitude:southWest.latitude longitude:southWest.longitude];
        CLLocation *locNorthEast = [[CLLocation alloc] initWithLatitude:northEast.latitude longitude:northEast.longitude];

        CLLocationDistance meters = [locSouthWest distanceFromLocation:locNorthEast];

        MKCoordinateRegion region;
        region.center.latitude = (southWest.latitude + northEast.latitude) / 2.0;
        region.center.longitude = (southWest.longitude + northEast.longitude) / 2.0;
        region.span.latitudeDelta = meters …
Run Code Online (Sandbox Code Playgroud)

iphone cocoa-touch objective-c mapkit ios

14
推荐指数
2
解决办法
1万
查看次数

标签 统计

cocoa-touch ×1

ios ×1

iphone ×1

mapkit ×1

objective-c ×1