我有一种方法可以移动 map ,使其跟随当前用户位置。这工作正常,但目前缩放比例不能按我想要的方式工作。我希望用户能够按照他们想要的方式缩小或放大 map ,并且仍然让它按照用户刚刚在 map 上设置的新缩放比例跟随当前位置。
我尝试执行以下操作,但效果不佳:
/**
* Centers the map on the current location
*
* @version $Revision: 0.1
*/
- (void)centerMapOnLocation:(CLLocation *)location {
// Make a region using our current zoom 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描述了如何获取当前 View 窗口。
当您创建新的 MKCoordinateRegion
以将新 View 设置为时,使用允许您指定大小的构造函数:
UIKIT_STATIC_INLINE MKCoordinateRegion MKCoordinateRegionMake(
CLLocationCoordinate2D centerCoordinate,
MKCoordinateSpan span
);
您需要传入当前区域的 span
和用户位置的 centerCoordinate
,我认为您已经知道了。
关于iphone - MKMapView:使用当前缩放级别关注当前位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7707864/