我有一點問題。 我只想在地圖視圖的中心顯示當前用戶位置。並且mapview縮放到可以同時顯示註釋和用戶位置的區域。 mapview的showAnnotation func似乎有所幫助,而用戶位置不在mapview的中心。iOS MapView在visibleRect中顯示當前位置和註釋
-1
A
回答
0
var userLoc = self.mapView.userLocation
let newDistance = CLLocation(latitude: userLoc.coordinate.latitude, longitude: userLoc.coordinate.longitude).distanceFromLocation(CLLocation(latitude: annotation.latitude, longitude: annotation.longitude))
let region = MKCoordinateRegionMakeWithDistance(userLoc.coordinate,2 * newDistance, 2 * newDistance)
let adjustRegion = self.mapView.regionThatFits(region)
self.mapView.setRegion(adjustRegion, animated:true)
上面的代碼解決了我的問題。我只是忘記乘以2的距離。 ...
-1
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance(userLocation.coordinate, 800, 800);
[self.mapView setRegion:[self.mapView regionThatFits:region] animated:YES];
}
上述代碼行指示地圖視圖可以放大用戶位置周圍800米乘800米的區域。
0
您可以使用:
_mapView.userTrackingMode = MKUserTrackingModeFollow
MKUserTrackingMode
將在地圖跟隨用戶的位置
相關問題
- 1. mapView在IO中顯示特定位置和註釋
- 2. SKMapView(Skobbler)上沒有顯示用戶當前位置註釋 - iOS
- 3. MapView返回到當前位置註解?
- 4. 顯示無Mapview註釋
- 5. 如何在mapview中顯示pin註釋?
- 6. 顯示MKMapView以一次顯示多個註釋和當前用戶位置
- 7. 如何在android mapview中精確顯示當前位置?
- 8. 如何在MapView上每10秒顯示一次當前位置?
- 9. iphone mapview當前位置
- 10. 當前位置的iPhone mapKit註釋
- 11. 鈦 - Mapview和註釋
- 12. 如何在地圖上顯示當前位置和所有註釋針腳iOS 8
- 13. iOS地圖標記和當前位置沒有顯示
- 14. 如何在mapview中顯示我目前的位置(GPS)
- 15. 如何使註釋看起來像當前位置指示符?
- 16. 單擊按鈕時,如何使用用戶當前位置顯示註釋?
- 17. 如何在當前位置加載少量註釋?
- 18. 當前位置不在圖形頁面顯示出來(IOS)
- 19. 如何在iOS的tableViewCell上顯示當前位置
- 20. 如何從我的當前位置繪製一條路徑到我在mapView中設置的註釋針?
- 21. MapKit iPhone開發;當前位置和註釋
- 22. MapView的註釋
- 23. 在mapview中顯示動態註釋引腳
- 24. Mapkit:僅在當前視圖中顯示註釋
- 25. 如何在mapview上設置當前位置的監聽器?
- 26. 當前位置警報和點在iOS8中未顯示
- 27. iOS SDK中當前位置的方位
- 28. 如何將mapView註釋從一個位置移動到另一個位置?
- 29. 自定義MKMapView註釋顯示不顯示用戶位置
- 30. 將當前光標位置顯示爲當前行和當前列?
通過地圖視圖覆蓋的區域是_region_。設置該地區取決於你。你可以在中心指定你想要的點,然後你可以指定區域。因此,將用戶位置顯示爲中心,但指定足夠大的區域以包含註釋。 – matt 2014-12-08 02:48:48
請參閱http://stackoverflow.com/questions/26416587/fitting-annotations-on-a-mkmapview-while-keeping-user-position-centered – Anna 2014-12-08 02:55:37