[英]MKMapView: Follow Current Location with current zoom level
我有一個方法可以移動地圖,使其跟隨當前用戶位置。 這工作正常,但目前縮放比例不是我想要的工作。 我希望用戶能夠縮小或放大地圖他們想要的方式,並且仍然按照用戶剛剛在地圖上設置的新縮放比例的當前位置。
我試着做以下但是效果不好:
/**
* 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縮放和區域描述了如何獲取當前視圖窗口。
當您創建新的MKCoordinateRegion
以將新視圖設置MKCoordinateRegion
,請使用允許您指定大小的構造函數:
UIKIT_STATIC_INLINE MKCoordinateRegion MKCoordinateRegionMake(
CLLocationCoordinate2D centerCoordinate,
MKCoordinateSpan span
);
你會想在傳遞span
從當前區域和centerCoordinate
從用戶的位置,我會認為你已經有了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.