2016-11-22 5 views
1

私のアプリケーションで、現在の場所から目的地までの経路をユーザーが確認できる機能を実装しています。ユーザーがボタンをタップすると、私は、Googleマップが私の現在の場所を選ぶことがようsaddrのparam空のままにすることで、このGoogleマップがまだ実行されていないと、Googleマップで経路が正しく表示されない

if UIApplication.sharedApplication().canOpenURL(NSURL(string:"comgooglemaps://")!) { 

      let urlStr = String(format: "comgooglemaps://?saddr=&daddr=%f,%f&directionsmode=driving&zoom=14", lat, lng) 
      let url = NSURL(string:urlStr)! 
      UIApplication.sharedApplication().openURL(url) 

} 

のようなGoogleマップアプリを開きます。しかし、Googleマップが既に実行されていない場合、Googleマップはルートを初めて表示しません。現在の位置のみが表示され、ローディングサークルが表示されます。しかし、Google Mapsが稼働していて、地図を開いて経路を表示するとうまくいきます。

誰も同じ問題に直面しましたか?どんな助けもありがとう。おかげ

答えて

1

LETカメラ= GMSCameraPosition.cameraWithLatitude(0、経度:-165、ズーム:2) せのMapView = GMSMapView.mapWithFrame(CGRectZero、カメラ:カメラ)1として

let path = GMSMutablePath() 
path.addLatitude(-33.866, longitude:151.195) // Sydney 
path.addLatitude(-18.142, longitude:178.431) // Fiji 
path.addLatitude(21.291, longitude:-157.821) // Hawaii 
path.addLatitude(37.423, longitude:-122.091) // Mountain View 

let polyline = GMSPolyline(path: path) 
polyline.strokeColor = UIColor.blueColor() 
polyline.strokeWidth = 5.0 
polyline.map = mapView 

self.view = mapView 

}

+0

Googleドキュメント – raheem

+0

回答ありがとう@raheem。しかし、このコードはアプリケーション内にマップを描画しますが、別のアプリケーションとしてGoogleマップを開くことについて話しています。 – umali

+0

UIApplication * app = [UIApplication sharedApplication]; \t \t NSURL * url = [NSURL URLWithForm:@ "comgooglemaps://" saddr =%f、%f&daddr =%f、%f "、self.startLocation.latitude、self.startLocation.longitude 、self.destinationLocation.latitude、self.destinationLocation.longitude] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; \t [app openURL:url]; – raheem

関連する問題