问题
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