New Xcode beta new problems: MKGeodesicPolyline
Asked Answered
S

2

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.

Submariner answered 8/7, 2016 at 16:53 Comment(1)
Can you try to define coordinates as UnsafeMutablePointer<CLLocationCoordinate2D>?Disciple
H
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

Horus answered 8/7, 2016 at 17:36 Comment(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.Submariner
C
0

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

  • remove "&" symbol before the coordinates . This solved the issue.
Chapman answered 30/5, 2017 at 12:41 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.