[英]Google Maps Navigation in Android
我正在使用Android,正在構建一個要在2點之間導航的應用程序。 我已經有了要點。 我在谷歌地圖上也有它們之間的路線。 我只想在它們之間導航。 您能幫我嗎?
考慮到您有兩個位置的來源,目的地,下面的代碼將您重定向到google導航,將其作為方法並在需要時調用!..讓我知道您是否需要其他幫助
Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://ditu.google.cn/maps?f=d&source=s_d" +
"&saddr="+source.getLatitude()+
","+source.getLongitude()+"&daddr="+
destination.latitude+
","+destination.longitude+
"&hl=zh&t=m&dirflg=d"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK & Intent.FLAG_ACTIVITY_EXCLUDE_FROM_RECENTS);
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivityForResult(intent, 1);
您可以嘗試使用Directions API 。
Google Maps Directions API是一項使用HTTP請求計算位置之間的方向的服務。
該服務通常設計用於計算用於將應用程序內容放置在地圖上的靜態(預先已知)地址的方向,但是該服務並非設計用於實時響應用戶輸入。
Google Maps Directions API請求采用以下形式:
https://maps.googleapis.com/maps/api/directions/output?參數
其中輸出可能是以下值之一:
json(推薦)指示以JavaScript對象表示法(JSON)輸出
xml表示輸出為XML
要通過HTTP訪問Google Maps Directions API,請使用:
http://maps.googleapis.com/maps/api/directions/output?參數
建議將HTTPS用於在請求中包含敏感用戶數據(例如用戶位置)的應用程序。
您需要此參數來獲取路線:
origin
您希望從中計算路線的地址,文本緯度/經度值或地點ID。
destination
-您要計算路線的地址,文本緯度/經度值或地點ID。 如上所述,目標參數的選項與原始參數的選項相同。
另請參閱本教程以獲取更多信息。
一切正常。
String uri = "http://maps.google.com/maps?f=d&hl=en&saddr="+startingLocation.latitude+","+startingLocation.longitude+"&daddr="+destinationLocation.latitude+","+destinationLocation.longitude;
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
startActivity(Intent.createChooser(intent, "Select an application"));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.