当前位置的自定义标注

Sur*_*rma 5 iphone mkmapview mkannotation

我想在标注中显示当前位置的2行标签. MKUserLocation而不是MKAnnotation 任何人可以帮忙解决这个问题吗?

我相信它可以使用自定义Callout ..但不确定如何为MKUserLocation创建它.

Mat*_*Mat 5

在该viewForAnnotation方法中,您可以尝试这样做:

- (MKAnnotationView *)map:(MKMapView *)map viewForAnnotation:(id <MKAnnotation>) annotation{
    if(self._mapView.userLocation==annotation){
       self._mapView.userLocation.title=@"some text";
       self._mapView.userLocation.subtitle=@"some text";
       return nil;
    }
}
Run Code Online (Sandbox Code Playgroud)

希望这可以帮助.


cha*_*tur 3

我假设您可以创建自定义注释标注,并希望使用用户定位代替默认标注。要完成此操作,需要获取当前位置 MKAnnotationView 的引用。人们可以在任何地方获取此参考,但最好在确定用户位置后立即获取它。

 - (void)mapView:(MKMapView *)mapView didUpdateUserLocation:(MKUserLocation *)userLocation 
    {
     MKAnnotationView* annotationView = [mapView viewForAnnotation:userLocation];
    annotationView.canShowCallout = NO;

//your customization here

    }
Run Code Online (Sandbox Code Playgroud)

或者使用下面的方法

- (void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views {
    MKAnnotationView *aV; 
         for (aV in views) {
                if ([aV.annotation isKindOfClass:[MKUserLocation class]]) {
                    MKAnnotationView* annotationView = aV;
                     annotationView.canShowCallout = NO;
    //your customization here

                }
        }
}
Run Code Online (Sandbox Code Playgroud)

如果想在运行时更改canShowCallout属性,则可以使用以下

    for (AnnotationClass* annotation in mapView.annotations) 
        {
            if([annotation isKindOfClass:[MKUserLocation class]] )
            {
                 MKAnnotationView* annotationView = [mapView viewForAnnotation:annotation];
                 annotationView.canShowCallout = NO;
//your customization here

            }
        }
Run Code Online (Sandbox Code Playgroud)