点击表示userLocation的脉动蓝色圆圈会显示“当前位置”标注。有没有办法压制它?
答案 0 :(得分:18)
一旦用户位置更新,您可以更改注释视图中的属性:
- (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation
{
MKAnnotationView *userLocationView = [mapView viewForAnnotation:userLocation];
userLocationView.canShowCallout = NO;
}
答案 1 :(得分:17)
您可以将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实例。
答案 2 :(得分:1)
Swift 4
// MARK: - MKMapViewDelegate
func mapViewDidFinishLoadingMap(_ mapView: MKMapView) {
if let userLocationView = mapView.view(for: mapView.userLocation) {
userLocationView.canShowCallout = false
}
}
答案 3 :(得分:1)
Swift 4 - Xcode 9.2 - iOS 11.2
// MARK: - MKMapViewDelegate
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if let userLocation = annotation as? MKUserLocation {
userLocation.title = ""
return nil
}
// ...
}
答案 4 :(得分:0)
我有两种方法可以帮助你:
在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
}
答案 5 :(得分:0)
当MKAnnotationView
添加用户MKAnnotationView
canShowCallout
属性mapView
设置为false
func mapView(_ mapView: MKMapView, didAdd views: [MKAnnotationView]) {
for view in views {
if view.annotation is MKUserLocation {
view.canShowCallout = false
}
}
}
答案 6 :(得分:0)
嘿,有一个更新的简单解决方案
迅速:
mapView.userLocation.title = "";
.net for iOS(Xamarin.iOS)
NativeMap.UserLocation.Title = "";
关于;)