how to get visible overlays in MapKit? (i.e. MKOverlay/MKOverlayRender from a Mapkit Ivew)

十年热恋 提交于 2019-12-08 12:15:33

问题


How does one get a list (array) of currently visible overlay from a MapkitView?

Background - for example I want to show direction arrows to the center of certain Overlay types on my mapkitview, however how do I get the visible ones? There seems to be no way to do this I can see? So do I need to got through all overlays (actually ~8000) and do my own check to see what would be showing on the screen? Seems a waste if MapKit would have already effectively done this as part of deciding what overlays need to be displayed at a given time.


回答1:


I've been tinkering with some similar problems and the most efficient way I could figure out was to add the overlays as annotations as well, since MKOverlay implements MKAnnotation. Then you would be able to use annotationsInMapRect for the currently displayed mapRect. However this would also return any regular MKAnnotations, and only uses the calculated middle of the overlay. The only way (so far as I figured) to only get the overlays would be to iterate over each overlay and use:

-(BOOL)intersectsMapRect:(MKMapRect)mapRect;

on the currently visible mapRect. If you found another way I'd be happy to hear!



来源:https://stackoverflow.com/questions/37433336/how-to-get-visible-overlays-in-mapkit-i-e-mkoverlay-mkoverlayrender-from-a-ma

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