iPhone SDK:MapKit多个自定义注释 [英] iPhone SDK: MapKit multiple custom annotations

查看:175
本文介绍了iPhone SDK:MapKit多个自定义注释的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够加载位置的大名单到我MapKit和自定义PIN形象和注释显示它们。

我遇到的问题是,我现在有显示同一标题的所有注释,字幕和pinImage。

我如何让这样我就可以有自己的标题和不同的针图像设置每个注释?
我有一个困难时期试图找出什么注解是通过图形页面被设置:viewForAnnotation

   - (的NSString *){字幕    返回@这是标注字幕。
} - (的NSString *){称号
    返回@批注标题;
} - (MKAnnotationView *)的MapView:(*的MKMapView)的MapView viewForAnnotation:(ID< MKAnnotation>){注解
    如果(注释== mapView.userLocation){
        回零;
    }    MKAnnotationView * annView = [[MKAnnotationView页头] initWithAnnotation:注释reuseIdentifier:@currentloc];
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5,5);
    *的UIImage = pinImage [UIImage的imageNamed:@mapPin.png];
    annView.image = pinImage;
    返回annView;
}


解决方案

您需要将注释对象投射到您的自定义类型和访问它的属性适当地改变你返回annotationView。

苹果WeatherMap样本项目是如何做到这一点的好例子。的https://developer.apple.com/library/ios/#sample$c$c/WeatherMap/Introduction/Intro.html

该MapCallouts示例项目是一样的想法,但一个简单的实现。的https://developer.apple.com/library/ios/#sample$c$c/MapCallouts/Introduction/Intro.html

I am able to load a big list of location onto my MapKit and display them all with a custom Pin image and annotation.

The issue i'm having is that I currently have all annotations displaying the same Title, Subtitle, and pinImage.

How do I make it so that I can set each annotation with its own Title and different Pin image? I'm having a hard time trying to identify what annotation is being setup via mapView:viewForAnnotation.

- (NSString *)subtitle{

    return @"This is the annotation subtitle.";
}

- (NSString *)title{
    return @"Annotations Title";
}

- (MKAnnotationView *) mapView:(MKMapView *)mapView viewForAnnotation:(id <MKAnnotation>)annotation {
    if (annotation == mapView.userLocation) {
        return nil;
    }

    MKAnnotationView *annView=[[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:@"currentloc"];
    annView.canShowCallout = YES;
    annView.calloutOffset = CGPointMake(-5, 5);
    UIImage *pinImage = [UIImage imageNamed:@"mapPin.png"];
    annView.image = pinImage;
    return annView;
}

解决方案

You'll need to cast the annotation object to your custom type and access it's properties to appropriately change the annotationView that you return.

Apple's WeatherMap sample project is a good example of how to do this. https://developer.apple.com/library/ios/#samplecode/WeatherMap/Introduction/Intro.html

The MapCallouts sample project is the same idea, but a simpler implementation. https://developer.apple.com/library/ios/#samplecode/MapCallouts/Introduction/Intro.html

这篇关于iPhone SDK:MapKit多个自定义注释的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆