如何让mapview中的应用用户丢弃多个引脚?

时间:2013-08-09 12:12:42

标签: iphone ios xcode map mkmapview

如何编写地图视图,用户可以在其中删除多个图钉,进行注释和添加图片?

我知道如何在Xcode中编写地图视图代码以及如何设置预设的插针但是我希望能够编写更复杂的代码,因为它与我希望创建的应用程序相关!

1:如何让应用程序的用户删除多个引脚以指定某个位置?

2:一旦用户丢了一个针我想要他能添加注释和图片吗?

我已经广泛使用了这个,虽然我已经找到了如何将基本地图编码到应用程序中但我无法对后续部分进行编码!

感谢您阅读我的问题,非常感谢您提出的任何建议。如果您认为有一个有用的YouTube视频或博客,您认为可以帮助我,请把它放在底部,我会仔细研究它!

1 个答案:

答案 0 :(得分:0)

首先创建一个实现<MKAnnotation>协议的Annotation类:

@interface Annotation : NSObject <MKAnnotation>
{
    CLLocationCoordinate2D location;
    NSString *title;
    NSString *subtitle;
    NSString *otherInfo;
    UIImage *image;
    // etc...any other info you want to include with your annotation
}

然后当你想放一个别针时:

-(void)dropPin:(CLLocationCoordinate2D *)location (NSString *)title (NSString *)subtitle (NSString *)otherInfo (UIImage *)image
{
    Annotation *pin = [Annotation annotationWithCoordinate:location];
    pin.title = title;
    pin.subtitle = subtitle;
    pin.otherInfo = otherInfo;
    pin.image = image;
    [self.mapView addAnnotation:pin];
}

您可能还希望将丢弃的引脚存储在数组或其他内容中,以便您可以跟踪它们并在以后引用它们。

有关更多信息和示例,请查看MKAnnotation协议的 MapKit documentation。另请阅读this tutorial,其中概述了如何使用MapKit对象和协议,包括注释。