Launching Google Maps Directions via an intent on Android

后端 未结 15 1637
小鲜肉
小鲜肉 2020-11-22 03:46

My app needs to show Google Maps directions from A to B, but I don\'t want to put the Google Maps into my application - instead, I want to launch it using an Intent. Is this

15条回答
  •  佛祖请我去吃肉
    2020-11-22 04:21

    You could use something like this:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
        Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
    startActivity(intent);
    

    To start the navigation from the current location, remove the saddr parameter and value.

    You can use an actual street address instead of latitude and longitude. However this will give the user a dialog to choose between opening it via browser or Google Maps.

    This will fire up Google Maps in navigation mode directly:

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
        Uri.parse("google.navigation:q=an+address+city"));
    

    UPDATE

    In May 2017 Google launched the new API for universal, cross-platform Google Maps URLs:

    https://developers.google.com/maps/documentation/urls/guide

    You can use Intents with the new API as well.

提交回复
热议问题