2017-05-29 116 views
0

我能夠與Android - 如何在駕駛模式中啓用Google地圖意圖?

Uri location = Uri.parse("geo:0,0"); 
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location); 
startActivity(mapIntent); 

推出谷歌地圖的意圖如何可以啓動在駕駛模式的意圖(無目的地,除非事先在地圖設置),這樣它看起來像下面的截圖?

enter image description here

我試着設置mode=driving但只開啓普通地圖中選擇「驅動」選項卡:

Uri location = Uri.parse("geo:0,0?mode=driving"); 

回答

2

這將啓動谷歌地圖在驅動方式

Intent intent = getPackageManager().getLaunchIntentForPackage("com.google.android.apps.maps"); 
    intent.setAction(Intent.ACTION_VIEW); 
    intent.setData(Uri.parse("google.navigation:/?free=1&mode=d&entry=fnls")); 
    startActivity(intent); 
1

我明白你想在導航模式打開谷歌地圖應用。爲了這個目的,你可以使用谷歌地圖的URL API中所描述的URL:

https://developers.google.com/maps/documentation/urls/guide#directions-action

下面的代碼應該做的一招,我相信你需要提供目標參數,直接打開該模式

String URL = "https://www.google.com/maps/dir/?api=1&travelmode=driving&dir_action=navigate&destination=Los+Angeles"; 
Uri location = Uri.parse(URL); 
Intent mapIntent = new Intent(Intent.ACTION_VIEW, location); 
startActivity(mapIntent); 

我希望這有助於!

+0

你是對的,它需要的目標使用travelmode =駕駛。我想知道是否有辦法在沒有目的地的情況下進入駕駛模式,如下所述:http://fieldguide.gizmodo.com/google-maps-driving-mode-is-your-essential-in-car-ai- 1776306949 –

相關問題