【发布时间】:2015-08-26 19:34:53
【问题描述】:
我有这些方法可以在两个CLLocation 之间为 MKMapView 添加路由。我有两个有效的 pickUpDistanceLocation 和 dropOffDistanceLocation
func addRoutesOverLayForMapView(){
var source:MKMapItem?
var destination:MKMapItem?
println("\(pickUpDistanceLocation)")
println("\(dropOffDistanceLocation)")
//i also tested with these locations
//let sourcelocation = CLLocation(latitude: 40.7141667, longitude: -74.0063889)
//let destinationLocation = CLLocation(latitude: 38.89, longitude: 77.03)
CLGeocoder().reverseGeocodeLocation(pickUpDistanceLocation, completionHandler: {(placemarks,error)-> Void in
if (error != nil) {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
if let placemark: MKPlacemark = placemarks![0] as? MKPlacemark {
source = MKMapItem(placemark: placemark)
println("\(source)")
}
} else {
println("Problem with the data received from geocoder")
}
})
CLGeocoder().reverseGeocodeLocation(dropOffDistanceLocation, completionHandler: {(placemarks,error)-> Void in
if (error != nil) {
println("Reverse geocoder failed with error" + error.localizedDescription)
return
}
if placemarks.count > 0 {
if let placemark: MKPlacemark = placemarks![0] as? MKPlacemark {
destination = MKMapItem(placemark: placemark)
println("\(destination)")
}
} else {
println("Problem with the data received from geocoder")
}
})
let request:MKDirectionsRequest = MKDirectionsRequest()
request.setSource(source)
request.setDestination(destination)
request.transportType = MKDirectionsTransportType.Automobile
request.requestsAlternateRoutes = false
let directions = MKDirections(request: request)
directions.calculateDirectionsWithCompletionHandler ({
(response: MKDirectionsResponse?, error: NSError?) in
if error == nil {
self.showRoute(response!)
}
})
}
这是在地图中添加路线覆盖的方法
func showRoute(response:MKDirectionsResponse){
for route in response.routes as! [MKRoute]{
mapView.addOverlay(route.polyline, level: MKOverlayLevel.AboveRoads)
}
}
我收到此错误,因为响应返回错误:400
打印错误时显示为
Optional("操作无法完成。(NSURLErrorDomain 错误 -1011.)")
【问题讨论】:
-
根据 OSStatus,这看起来是服务器错误:osstatus.com/search/…
-
那我该怎么办?我尝试过使用不同的经纬度
-
如果错误是服务器端的,在 Apple 解决之前您无能为力。
标签: ios swift routes mkmapview