开发者

iPhone Map: Distinguishing Users Location from Other Pins

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] initWithAnno开发者_Go百科tation:annotation reuseIdentifier:identifier] autorelease];
        pinView.rightCalloutAccessoryView = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
        pinView.animatesDrop = YES;
        pinView.canShowCallout = YES;
    }
    else
    {
        pinView.annotation = annotation;
    }

    return pinView;
}


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
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜