I have 30 annotations, and growing. Looking for a simpler way to code this?

馋奶兔 提交于 2019-12-03 17:45:47

The MapCallouts sample app unfortunately doesn't give a good example of how to implement a generic annotation class.

Your class that implements the MKAnnotation protocol can provide a settable coordinate property or a custom init method that takes the coordinates.

However, since you're using iOS 4.0, an easier option is to just use the pre-defined MKPointAnnotation class that provides properties that you can set. For example:

MKPointAnnotation *annot = [[MKPointAnnotation alloc] init];
annot.title = @"Title";
annot.subtitle = @"Subtitle";
annot.coordinate = CLLocationCoordinate2DMake(-45.866416, 170.519931);
[mapView addAnnotation:annot];
[annot release];

The annotation data can of course come from anywhere and you can loop through the data to create the annotations on the map.

Kolya Miller

Perhaps create an array of dictionary items of annotations (lat,lon,title,subtitle) and store in a plist?

Or maybe use the core data framework and store the items in a sqlite db?

Maybe this link will also help? Display a limited number of sorted annotations in Mapview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!