iPhone 地图:区分用户位置和其他 Pin 图
除了用户当前位置之外,我的地图上还有许多注释。这工作得很好,除了用户当前位置的默认颜色与所有其他注释相同。我想将用户当前位置的引脚设置为绿色,以便可以从其他引脚中唯一地识别它。我该怎么做?
以下是我一直在使用的方法(我找不到方法来确定哪个注释是用户当前位置):
- (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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用标准 MKUserLocation 类型作为用户位置,那么您可以检查注释的类型是否相同:
If you use standard
MKUserLocation
type for user location then you can check annotation's type if it is the same: