2015-10-16 72 views
0

我想在不使用Google API的情況下在地圖上繪製路線。如何繪製路線(沒有多段線)和沒有谷歌API?

我正在跟蹤用戶的座標。所以我畫多段線來顯示用戶路線,但現在我的客戶想要刪除這些多段線並想顯示像谷歌一樣的路線。是否有可能通過這些座標上繪製的所有座標路線圖?

回答

1

其實你可以使用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/