2015-05-21 24 views
-1

我正在开发Android Studio中的Android应用程序,当用户点击按钮时,我想要在Android设备上启动内置的Google地图应用程序。我还想让地图在Google地图应用的路线部分显示给定的目的地(来自我自己的应用)。有谁知道如何去做这件事?启动内置谷歌地图应用程序

回答

1

您可以使用此代码来实现此目的。

String url = "http://maps.google.com/maps?saddr="+currentLattitude+","+currentLongitude+"&daddr="+targetLat+","+targetLang+"&mode=driving"; 
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url)); 
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity"); 
startActivity(intent); 

可以使用dirflg参数为:

dirflg=h - Switches on "Avoid Highways" route finding mode. 
dirflg=t - Switches on "Avoid Tolls" route finding mode. 
dirflg=r - Switches on "Public Transit" - only works in some areas. 
dirflg=w - Switches to walking directions - still in beta. 
dirflg=d - Switches to driving directions 

参考this SO发布答案的更多细节。

相关问题