2017-11-09 6 views
1

マップやGoogleマップアプリを使用せずにMKMapViewで経路やルートを取得しようとしています。 他のアプリを開いてアプリで使用したいです。 誰かを助けることができますか?MKMapViewで方向とルートを取得

これは私が持っているものですが、私はそれを変更したいので、私のアプリで方向とルーティングを得ることができます。私はSwift 4とXcode 9を持っています!

//Getting direction of location 
    @objc func getDirections(){ 
     if let selectedPin = selectedPin { 
      let mapItem = MKMapItem(placemark: selectedPin) 
      let launchOptions = [MKLaunchOptionsDirectionsModeKey : MKLaunchOptionsDirectionsModeDriving] 
      mapItem.openInMaps(launchOptions: launchOptions) 
     } 
    } 


extension ViewController : MKMapViewDelegate { 
    func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?{ 
     if annotation is MKUserLocation { 
      //return nil so map view draws "blue dot" for standard user location 
      return nil 
     } 
     let reuseId = "pin" 
     var pinView = mapView.dequeueReusableAnnotationView(withIdentifier: reuseId) as? MKPinAnnotationView 
     pinView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: reuseId) 
     pinView?.pinTintColor = UIColor.red 
     pinView?.canShowCallout = true 
     let smallSquare = CGSize(width: 30, height: 30) 
     let button = UIButton(frame: CGRect(origin: CGPoint.zero, size: smallSquare)) 
     button.setBackgroundImage(UIImage(named: "Car"), for: .normal) 
     button.addTarget(self, action: #selector(getDirections), for: .touchUpInside) 

     pinView?.leftCalloutAccessoryView = button 
     return pinView 
    } 
} 

答えて

1

私は地図やGoogleマップのアプリを使用せずにMKMapViewとの方向とルートを取得しようとしています。 他のアプリを開いてアプリで使用したいです。助けてもらえますか?

アプリ内でナビゲーションを開始することはできません。あなたができることは、2つのポイント間のパスを描き、距離や予想される運転/歩行時間などの情報を得ることです。

Distance between two points MapKitを検索すると、多数の結果が見つかります。例えば、見てくださいherehereまたはthis swift 4 soultion

関連する問題