无法将 CLLocationCoordinate2D 转换为 (CLLocationCoordinate2D)
Cannot convert CLLocationCoordinate2D to (CLLocationCoordinate2D)
我的代码有问题。
我收到此错误消息:
Cannot convert value of type 'CLLocationCoordinate2D' to expected argument type '(CLLocationCoordinate2D) throws -> Bool'
if(locationManager.allowsBackgroundLocationUpdates && isDriving){
locationManager.startUpdatingLocation()
guard let locValue: CLLocationCoordinate2D = locationManager.location?.coordinate else { return }
Map.setCenter(locValue, animated: true)
Map.setRegion(MKCoordinateRegion(center: locValue, latitudinalMeters: 75, longitudinalMeters: 75), animated: true)
if !locations.contains(where: locValue) { //<- ERROR
locations.append(locValue);
NSLog("%f %f -> Gesamt: %d", locValue.latitude, locValue.longitude, locations.count);
let polyline = MKPolyline(coordinates: &locations, count: locations.count);
Map.addOverlay(polyline);
}
}
地点:
var locations = [CLLocationCoordinate2D]()
使用
extension CLLocationCoordinate2D : Equatable {
static public func ==(left: CLLocationCoordinate2D, right: CLLocationCoordinate2D) -> Bool {
return left.latitude == right.latitude && left.longitude == right.longitude
}
}
if !locations.contains(locValue){
}
要使用 contains
的数组,元素需要符合 Equatable
而由于 CLLocationCoordinate2D
不符合,那么错误修复需要您添加一个 where 子句来指定如何比较就像
CLLocationCoordinate2D
不符合Equatable
.
您必须在 where
闭包
中比较 latitude
和 longitude
if !locations.contains(where: {[=10=].latitude == locValue.latitude && [=10=].longitude == locValue.longitude}) { ...
我的代码有问题。 我收到此错误消息:
Cannot convert value of type 'CLLocationCoordinate2D' to expected argument type '(CLLocationCoordinate2D) throws -> Bool'
if(locationManager.allowsBackgroundLocationUpdates && isDriving){
locationManager.startUpdatingLocation()
guard let locValue: CLLocationCoordinate2D = locationManager.location?.coordinate else { return }
Map.setCenter(locValue, animated: true)
Map.setRegion(MKCoordinateRegion(center: locValue, latitudinalMeters: 75, longitudinalMeters: 75), animated: true)
if !locations.contains(where: locValue) { //<- ERROR
locations.append(locValue);
NSLog("%f %f -> Gesamt: %d", locValue.latitude, locValue.longitude, locations.count);
let polyline = MKPolyline(coordinates: &locations, count: locations.count);
Map.addOverlay(polyline);
}
}
地点:
var locations = [CLLocationCoordinate2D]()
使用
extension CLLocationCoordinate2D : Equatable {
static public func ==(left: CLLocationCoordinate2D, right: CLLocationCoordinate2D) -> Bool {
return left.latitude == right.latitude && left.longitude == right.longitude
}
}
if !locations.contains(locValue){
}
要使用 contains
的数组,元素需要符合 Equatable
而由于 CLLocationCoordinate2D
不符合,那么错误修复需要您添加一个 where 子句来指定如何比较就像
CLLocationCoordinate2D
不符合Equatable
.
您必须在 where
闭包
latitude
和 longitude
if !locations.contains(where: {[=10=].latitude == locValue.latitude && [=10=].longitude == locValue.longitude}) { ...