放大和缩小时的Mapkit注释类型?

发布于 2024-10-19 23:08:11 字数 235 浏览 5 评论 0原文

我正在使用 Mapkit 并且使用 SDK 4.2,我在这里遇到了一个奇怪的错误,事实上我有 3 种注释类型,“blue.png”、red.png、black.png。我通过通量加载它们,并根据类型选择这些注释类型。加载地图时一切正常,我有不同的注释视图,但是当我移动、放大或缩小注释视图时,注释视图会发生变化,即它应该是 blue.png 的地方,它变成了 black.png。

我实际上正在设备上测试它。

非常感谢 :)

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.png,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 :)

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

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

发布评论

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

评论(2

っ左 2024-10-26 23:08:11

嘿,问题是,如果用户平移地图以查看另一个位置,然后返回到绘制注释的位置,则会调用此方法。

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

我见过很多地图应用程序的示例代码,大多数人都在使用它。

- (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;
}

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;
}
柏林苍穹下 2024-10-26 23:08:11

我找到了解决方案 - 事实上我正在使用自定义注释视图并具有 3 种不同类型的图像:

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

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;
}
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文