从Android应用程序调用Google Map应用程序以获得指导方向

gan*_*esh 4 android google-maps android-intent


我需要使用外部谷歌地图应用程序显示行车方向我发现此链接 http://developer.android.com/guide/appendix/g-app-intents.html,但下面打开地图应用程序到指定位置

    Uri uri = Uri.parse("geo:13.070984,80.253639");
    Intent in = new Intent(Intent.ACTION_VIEW, uri);
    startActivity(in);
Run Code Online (Sandbox Code Playgroud)

我需要知道有没有办法通过两个地理位置来获得行车方向.

Din*_*rma 13

是的,如果您拥有源和目的地的纬度和经度,则很容易显示方向.只需看看以下代码:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
    Uri.parse("http://maps.google.com/maps?saddr="+latitude_source+","+longitude_source+"&daddr="+latitude_dest+","+longitude_dest));

    startActivity(intent);
Run Code Online (Sandbox Code Playgroud)

latitude_source=Latitude源的 longitude_source=Longitude源的 latitude_dest=Latitude目的地的 longitude_dest=Longitude目的地的

只需将这些值替换为您的实际数据即可..在某些特定事件上使用上述代码.

希望这会帮助你.

  • @ganesh,你的意思是你不想让意图选择器弹出,只想加载地图应用程序?然后添加这行代码`intent.setComponent(new ComponentName("com.google.android.apps.maps","com.google.android.maps.MapsActivity"));` (2认同)