4

The brand new Xcode version, in addition to removing a wide nume of place where to add an empty function call, introduced a funny problem with an simple piece of code drawing a geodetic path:

func drawPolyline(from startLocation: CLLocation, endLocation:CLLocation) {
    let point1 = startLocation.coordinate
    let point2 = endLocation.coordinate
    var points: [CLLocationCoordinate2D]
    points = [point1, point2]
    var coordinates=points[0]
    let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count:2)
    self.mapView.add(geodesic)
}

The compiler complaints about an:

Ambiguous use of 'init(coordinates:count:)'

When I try to click on the given options, I am always led to that line. I tried to clean the project to no avail.

Fabrizio Bartolomucci
  • 4,948
  • 8
  • 43
  • 75

2 Answers2

3

In this case MKGeodesicPolyline would use either UnsafePointer or UnsafeMutablePointer using the type CLLocationCoordinate2D which you defined as points, so you'd likely want:

let geodesic = MKGeodesicPolyline(coordinates: points, count: 2)

Apple Developer : CLLocation

l'L'l
  • 44,951
  • 10
  • 95
  • 146
  • 1
    In fact , the new beta does not apparently accept the subscribing: by using let geodesic = MKGeodesicPolyline(coordinates: points, count:2) it compiles without problems, even if the error returned for such a chang of syntax was much less than clear. I think all the examples on the web must be corrected. Many thanks. – Fabrizio Bartolomucci Jul 08 '16 at 17:54
0

let geodesic = MKGeodesicPolyline(coordinates: &coordinates, count:2)

  • remove "&" symbol before the coordinates . This solved the issue.
Harish
  • 537
  • 1
  • 4
  • 9