1

I need create menu with adding polyline or polygon on Map. I know how render MKPolyline and MKPolygon with list of annotations, but I don't know how create with gestures.

Thanks for help.

Z.S.
  • 39
  • 1
  • 9

1 Answers1

0

Some part of code was taken from here.

    let locations = [CLLocation(latitude: 37.582691, longitude: 127.011186), CLLocation(latitude: 37.586112,longitude: 127.011047), CLLocation(latitude: 37.588212, longitude: 127.010438)]
    var coordinates = locations.map({(location: CLLocation) -> CLLocationCoordinate2D in return location.coordinate})
    let polyline = MKPolyline(coordinates: &coordinates, count: locations.count)
    let polygon = MKPolygon(coordinates: &coordinates, count: locations.count)


let coordsPointer = UnsafeMutablePointer<CLLocationCoordinate2D>.alloc(polyline.pointCount)
polyline.getCoordinates(coordsPointer, range: NSMakeRange(0, polyline.pointCount))
var coords: [Dictionary<String, AnyObject>] = []
for i in 0..<polyline.pointCount {
    let latitude = NSNumber(double: coordsPointer[i].latitude)
    let longitude = NSNumber(double: coordsPointer[i].longitude)
    let coord = ["latitude" : latitude, "longitude" : longitude]
    coords.append(coord)
}
print(coords)
Community
  • 1
  • 1
Ramis
  • 13,985
  • 7
  • 81
  • 100