开发者

iPhone Map: Distinguishing Users Location from Other Pins

开发者 https://www.devze.com 2022-12-30 17:06 出处:网络
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 annotation

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

精彩评论

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