开发者

Mapkit Annotation type when zooming in and out?

i am working with Mapkit and i am on SDK 4.2, i am having a strange bug here, in fact i have 3 annotation types, "blue.png", red.开发者_如何学Pythonpng,black.png. I am loading these by a flux and depending on the type its will select these annotation types. Everything works fine when the map is loaded i have the the different annotation view, but when i move , zoom in or zoom out the annotation view changes i.e where it was supposed to be blue.png it becomes black.png.

I am actually testing it on device.

Thank you very much :)


Hey veer the problem is that this method is called if the user pans the map to view another location and then comes back to the place where the annotations are plotted.

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation

I have seen many sample code for map application and this in what most of the people are using.

- (MKAnnotationView *)mapView:(MKMapView *)mapview viewForAnnotation:(id <MKAnnotation>)annotation
{
    if ([annotation isKindOfClass:[MKUserLocation class]])
        return nil;
    static NSString* AnnotationIdentifier = @"AnnotationIdentifier";
    MKAnnotationView *annotationView = [mapView dequeueReusableAnnotationViewWithIdentifier:AnnotationIdentifier];
    if(annotationView)
        return annotationView;
    else
    {
        MKPinAnnotationView* pinView = [[[MKPinAnnotationView alloc]
                                         initWithAnnotation:annotation reuseIdentifier:AnnotationIdentifier] autorelease];
        pinView.animatesDrop=YES;
        pinView.canShowCallout=YES;
        pinView.draggable = YES;
        pinView.pinColor = MKPinAnnotationColorGreen;
        return pinView;
    }
    return nil;
}


i found the solution - in fact i am using a custom annotation view and having 3 diff types of images :

Soln:

- (AnnotationView *)mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation
{

    AnnotationView *annotationView = nil;

    // determine the type of annotation, and produce the correct type of annotation view for it.
    AnnotationDetails* myAnnotation = (AnnotationDetails *)annotation;

    if(myAnnotation.annotationType == AnnotationTypeGeo)
    {
// annotation for your current position
        NSString* identifier = @"geo";
        AnnotationView *newAnnotationView = (AnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(nil == newAnnotationView)
        {
            newAnnotationView = [[[AnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
        }

        annotationView = newAnnotationView;
    }
    else if(myAnnotation.annotationType == AnnotationTypeMyfriends)
    {
        NSString* identifier = @"friends";
AnnotationView *newAnnotationView = (AnnotationView *)[self.mapView dequeueReusableAnnotationViewWithIdentifier:identifier];

        if(nil == newAnnotationView)
        {
            newAnnotationView = [[[AnnotationView alloc] initWithAnnotation:myAnnotation reuseIdentifier:identifier] autorelease];
        }

        annotationView = newAnnotationView;
}
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜