點擊代表用戶位置的脈動藍色圓圈可調出「當前位置」標註。有沒有辦法抑制這一點?如何在地圖視圖中抑制「當前位置」標註
回答
有上標註視圖可以更改,一旦用戶的位置已經被更新的屬性:
您可以設置title
爲空白打壓標註:
mapView.userLocation.title = @"";
編輯:
一個更可靠的方式可能是空白標題中didUpdateUserLocation
委託方法:
-(void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
userLocation.title = @"";
}
或viewForAnnotation
:
- (MKAnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id<MKAnnotation>) annotation
{
if ([annotation isKindOfClass:[MKUserLocation class]])
{
((MKUserLocation *)annotation).title = @"";
return nil;
}
...
}
在委託方法中設置標題可以讓您確定您有一個真正的userLocation實例可以使用。
謝謝!我知道我可以更改標題和副標題,但不知道將標題設置爲空白字符串會抑制它。 – charudatta
通過@jowie回答更好。改爲使用該方法。 – Anna
@Anna一直在擺弄,但沒有取得成功 - 關於如何在不阻止'mapView:didSelectedAnnotationView:'被調用的情況下完全抑制默認標註泡泡(如上所述,是的,@jowie的答案可能更好)的任何想法? –
我有兩個方法可以幫助你:
抑制mapViewDidFinishLoadingMap
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { mapView.showsUserLocation = true //suppress the title mapView.userLocation.title = "My Location" //suppress other params
}
抑制didUpdate
func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { //suppress the title mapView.userLocation.title = "My Location" //suppress other params }
斯威夫特4
// MARK: - MKMapViewDelegate
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
if let userLocationView = mapView.view(for: mapView.userLocation) {
userLocationView.canShowCallout = false
}
}
- 1. 關注用戶在Titanium地圖視圖中的當前位置?
- 2. Swift 3中MKLocalSearch的註解 - 地圖視圖當前位置
- 3. iOS地圖視圖:自定義標註視圖位置調整
- 4. 如何移除默認的Google地圖當前位置圖標?
- 5. Arcgis地圖當前位置
- 6. 當前位置與地圖
- 7. 如何在地圖視圖中繪製從當前位置到目的位置的路線xamarin iOS
- 8. 如何在Google地圖上添加當前位置標記
- 9. 谷歌地圖API如何設置當前位置標記
- 10. 如何獲得當前位置在iphone上的地圖位置
- 11. 放大當前位置在地圖視圖
- 12. 如何在地圖中手動設置當前位置(sencha touch2)?
- 13. 谷歌地圖當前位置繪圖
- 14. 在當前位置顯示藍色圓點圖標Google地圖
- 15. Android中當前位置的地圖
- 16. 在地圖上顯示當前位置
- 17. 在地圖上獲取當前位置
- 18. 在地圖上的當前位置android
- 19. 如何在android中獲取地圖中的當前位置?
- 20. 在地圖視圖中設置位置
- 21. 將地圖置於當前位置 - Titanium
- 22. 谷歌地圖在當前位置設置標記
- 23. 如何在Android中查找當前位置的谷歌地圖?
- 24. 如何在Google地圖中顯示設備的當前位置?
- 25. 如何在百度地圖中顯示當前位置android
- 26. 如何重定向在谷歌地圖中的當前位置
- 27. 如何在谷歌地圖iOS中查找當前位置?
- 28. 如何製作顯示您的當前位置的地圖視圖,類似於Google地圖?
- 29. 在iPhone中需要時在地圖上定製圖標和默認當前位置圖標
- 30. 如何在iphone中獲取當前位置在地圖上的座標值?
有時無法確定位置,MKUserLocation變爲灰色。在這種情況下,標註仍在顯示。這個答案不正確。 – Andy
單獨做這件事對我來說不適用於iOS 10.在'viewForAnnotation'中的處理工作。 –