2011-11-29 38 views

回答

15

有上标注视图可以更改,一旦用户的位置已经被更新的属性:

+0

有时无法确定位置,MKUserLocation变为灰色。在这种情况下,标注仍在显示。这个答案不正确。 – Andy

+0

单独做这件事对我来说不适用于iOS 10.在'viewForAnnotation'中的处理工作。 –

12

您可以设置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实例可以使用。

+0

谢谢!我知道我可以更改标题和副标题,但不知道将标题设置为空白字符串会抑制它。 – charudatta

+0

通过@jowie回答更好。改为使用该方法。 – Anna

+0

@Anna一直在摆弄,但没有取得成功 - 关于如何在不阻止'mapView:didSelectedAnnotationView:'被调用的情况下完全抑制默认标注泡泡(如上所述,是的,@jowie的答案可能更好)的任何想法? –

0

我有两个方法可以帮助你:

  1. 抑制mapViewDidFinishLoadingMap

    func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { 
    mapView.showsUserLocation = true 
    //suppress the title 
    mapView.userLocation.title = "My Location" 
    //suppress other params 
    

    }

  2. 抑制didUpdate

    func mapView(_ mapView: MKMapView, didUpdate userLocation: MKUserLocation) { 
        //suppress the title 
        mapView.userLocation.title = "My Location" 
        //suppress other params 
    } 
    
0

斯威夫特4

// MARK: - MKMapViewDelegate 

func mapViewDidFinishLoadingMap(_ mapView: MKMapView) { 
    if let userLocationView = mapView.view(for: mapView.userLocation) { 
     userLocationView.canShowCallout = false 
    } 
} 
相关问题