User creating a box on MKMapView

半城伤御伤魂 提交于 2020-01-06 17:14:10

问题


I have an app that I want the user to be able to dray a box around a location, say a parking lot. I can't figure out a good way to let them draw this. I can track a long press, and draw the MKPolygon from the touch points, but I would like them to be able to trace the parking lot, and then get the coordinate values for the corners.

I have no idea how to do this, and any help would be appreciated.


回答1:


A slightly different and probably easier approach you can try is to let the user specify the corners using draggable annotations.

To start "drawing", place two (or more) annotations to represent the corners of the box. Be sure to use an annotation class that implements setCoordinate: so it's draggable.

The user can drag the corners where they want and tap some button when done at which point you can create the MKPolygon using the annotation coordinates and then remove the annotations.

Or, you can re-create the MKPolygon every time the user finishes dragging an annotation (corner) and the user taps some button to say "done" and then you can remove the annotations.



来源:https://stackoverflow.com/questions/6931058/user-creating-a-box-on-mkmapview

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