[英]Google maps API in Android
我正在嘗試實現一種功能,以便當用戶在文本字段中輸入地址並單擊按鈕時,該地址應復制到Google地圖的目標字段中,並且用戶位置應設置為“我的位置”(他的當前位置)。
您可以通過以下方式打開Google地圖:
String CURRENT_LOCATION = "current_location_latitude, current_location_longitude";
String DESTINATION_LOCATION = "address_from_your_text_view";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?saddr="+ CURRENT_LOCATION +" daddr="+DESTINATION_LOCATION));
startActivity(intent);
注意:您應該從LocationManager獲取設備/用戶的當前位置
為了在Google Map上顯示路線,只需調用一個意圖即可傳遞當前和目的地的緯度和經度。 如果您不知道經緯度,也可以在任何情況下通過地址。 完成此操作后,其Google Map的工作將顯示位置。 您也可以顯示街景。
在下面的代碼中,有三個參數: current_lat, current_longi, dest_address
final Intent intent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+dest_address ));
intent.setClassName("com.google.android.apps.maps","com.google.android.maps.MapsActivity");
startActivity(intent);
如果您具有當前地址和目標地址,則可以這樣寫:
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+curr_address+ "&daddr="+dest_address ));
如果您同時具有當前和目標緯度和經度,則可以這樣編寫:
Uri.parse("http://maps.google.com/maps?"
+ "saddr="+ current_lat+","+current_longi + "&daddr="+ destt_lat+","+dest_longi ));
當您調用此意圖時,Google Map會顯示是通過公共汽車還是步行繪制路線的選項。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.