iPhone MapKit - update annotations coordinates and map

旧时模样 提交于 2019-12-04 16:24:28

At iPhone SDK 3.x you have to remove the pin annotations and set it again. That is not very nice if you have many annotations an your map.

I try to make it better so I ony display/renew my pin annotations which are on the screen. So if an user zoom in to New York, there won't be pin annotations in San Francisco or other than the user can't see. So the performance will be much better.

Perhaps in the future this would be possible. I hope so :-)

That tutorial is only for getting a map view to show, nothing else. You're going to need a bigger tutorial. I found this one useful:

http://blog.objectgraph.com/index.php/2009/04/02/iphone-sdk-30-playing-with-map-kit/

Probably what you'll need to do is to loop through all the annotations on the map, removing them, then loop through your data array, adding the annotations back again. You could be more clever about it and loop through the data array, checking if there's already a pin with the same latitude/longitude on the map, but that way gets more complicated.

Since I'm doing annotations at the moment I just made a quick test. You do get a compiler warning, so it might not be supported. But it works.

Make a custom MKAnnotation class so you can set the coordinate property to be writable:

@property (nonatomic, readwrite) CLLocationCoordinate2D coordinate;

Then at whatever event or interval you want, change the coordinate using something like this:

    CLLocation *loc=[[CLLocation alloc] initWithLatitude:55.0 longitude:17.0];
annotation.coordinate=loc.coordinate;
[loc release];
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!