我想在 map 上绘制路线而不使用 google API。
我正在使用用户坐标跟踪用户。所以我画折线来显示用户路线,但现在我的客户想要删除这些折线并想要显示像谷歌那样的路线。我是否可以传递在这些坐标上绘制的所有坐标路线图?
最佳答案
实际上,您可以使用 MKDirections
内置的 MapKit 框架。这是更多信息:https://developer.apple.com/library/mac/documentation/MapKit/Reference/MKDirections_class/ .
向您展示一些正在计算两个位置的路线的片段:
func caculateDirections(fromCoordinate: CLLocationCoordinate2D, toCoordinate: CLLocationCoordinate2D) {
let from = MKMapItem(placemark: MKPlacemark(coordinate: fromCoordinate, addressDictionary: nil))
let to = MKMapItem(placemark: MKPlacemark(coordinate: toCoordinate, addressDictionary: nil))
let request = MKDirectionsRequest()
request.source = from
request.destination = to
request.transportType = .Automobile
let directions = MKDirections(request: request)
directions.calculateDirectionsWithCompletionHandler { (response, error) -> Void in
if let response = response {
// Here you can get the routes and draw it on the map
let routes = response.routes
} else {
print("Error:\(error?.description)")
}
}
}
您可以从本教程中了解更多信息:http://www.devfright.com/mkdirections-tutorial/
关于ios - 如何在没有 google api 的情况下绘制路线(没有折线)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33165158/