iPhone 地图:区分用户位置和其他 Pin 图

发布于 2024-09-02 00:30:00 字数 863 浏览 0 评论 0原文

除了用户当前位置之外,我的地图上还有许多注释。这工作得很好,除了用户当前位置的默认颜色与所有其他注释相同。我想将用户当前位置的引脚设置为绿色,以便可以从其他引脚中唯一地识别它。我该怎么做?

以下是我一直在使用的方法(我找不到方法来确定哪个注释是用户当前位置):

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *identifier = @"Pin";
    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (pinView == nil)
    {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;
    }
    else
    {
        pinView.annotation = annotation;
    }

    return pinView;
}

I have a number of annotations on my map, in addition to the users current location. This works fine, except the default color for the users current location is the same as all of the other annotations. I'd like to make the pin green for the users current location so that it's uniquely identifiable from the other pins. How do I do this?

Bellow is the method I've been using (I can't find a way to determine which annotation is the users current location):

- (MKAnnotationView *)mapView:(MKMapView *)mapViewLocal viewForAnnotation:(id <MKAnnotation>)annotation {
    static NSString *identifier = @"Pin";
    MKPinAnnotationView *pinView = (MKPinAnnotationView*)[mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

    if (pinView == nil)
    {
        pinView = [[[MKPinAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:identifier] autorelease];
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;
    }
    else
    {
        pinView.annotation = annotation;
    }

    return pinView;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一口甜 2024-09-09 00:30:00

如果您使用标准 MKUserLocation 类型作为用户位置,那么您可以检查注释的类型是否相同:

...
if ([annotation isKindOfClass:[MKUserLocation class]]){
// This is annotation for user location
}

If you use standard MKUserLocation type for user location then you can check annotation's type if it is the same:

...
if ([annotation isKindOfClass:[MKUserLocation class]]){
// This is annotation for user location
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文