iOS MapKit: How Do I Get the Map to Pan During A Marker Drag?

旧城冷巷雨未停 提交于 2019-12-11 19:48:07

问题


I've looked in vain for answers on this.

In the Google Maps JavaScript API, when you drag a marker, and get close to the edge, the map pans to make room for the marker, and bring more of the map into view. This is very useful for starting at location A, then dragging to location B; even though B is currently off the map.

Apparently, this is not possible in MapKit. There does not seem to be any built-in functionality for this.

Fair enough. I'll write my own. I'll set up rects along the edges, and if the drag enters them, the map starts to pan. I'd accelerate the pan, based on the proximity to the edge.

Except: There also seems to be no way to get the marker location during a drag. You can only get it before and after. That kind of pooches my great idea.

I tested this by writing an NSTimer that is kicked off at the start of a drag, and invalidated at the end. It repeatedly calls a function that reads the annotation object for its location.

The location never changes during the drag.

Question: Any ideas on how I can get this "auto-pan" to work?


回答1:


Nope. Looks like you can't get there from here.

I did that, and the map seems to go into some kind of lock when you shift it. Looks like it can't deal with handling the marker when the coordinate system of the map underneath shifts.

I suspect that I now know why drag-panning is not supported.

I can hope that it will be supported in a later version of the MapKit.




回答2:


I agree with Anna Karenina -- respond to a long press on your annotation, hide the annotation view, replace it with a view above and outside of your map view, and respond to drags by adjusting the map view center in the opposite direction.



来源:https://stackoverflow.com/questions/19876071/ios-mapkit-how-do-i-get-the-map-to-pan-during-a-marker-drag

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