简体   繁体   English

iOS MapKit-在地图上绘制形状

[英]iOS MapKit - drawing shapes on map

I'd like to allow users to mark some area on map. 我想允许用户在地图上标记某些区域。 This area should be any closed shape. 该区域应该是任何封闭的形状。 For instance user can draw something like this: 例如,用户可以绘制如下内容:

在此处输入图片说明

In next step I'd like to calculate region of this shape. 在下一步中,我要计算此形状的区域。 How can I achive this? 我该如何实现?

You can use MKPolygon . 您可以使用MKPolygon

First of all you'll need to disable user interaction on the map view so that it won't move around while you're trying to draw on it. 首先,您需要在地图视图上禁用用户交互,以便在尝试绘制时不会移动。 Next up you can use the UIResponder functions touchesBegan , touchesMoved and touchesEnded . 接下来,您可以使用UIResponder函数touchesBegantouchesMovedtouchesEnded As you move through these three functions you can record the points the user has pressed. 当您浏览这三个功能时,可以记录用户按下的点。 Lastly you can then create an MKPolygon from this array of points that you have recorded. 最后,您可以根据已记录的点数组创建MKPolygon。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM