Launching Google Maps Directions via an intent on Android

后端 未结 15 1408
小鲜肉
小鲜肉 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:37

    Using the latest cross-platform Google Maps URLs: Even if google maps app is missing it will open in browser

    Example https://www.google.com/maps/dir/?api=1&origin=81.23444,67.0000&destination=80.252059,13.060604

    Uri.Builder builder = new Uri.Builder();
    builder.scheme("https")
        .authority("www.google.com")
        .appendPath("maps")
        .appendPath("dir")
        .appendPath("")
        .appendQueryParameter("api", "1")
        .appendQueryParameter("destination", 80.00023 + "," + 13.0783);
    String url = builder.build().toString();
    Log.d("Directions", url);
    Intent i = new Intent(Intent.ACTION_VIEW);
    i.setData(Uri.parse(url));
    startActivity(i);
    

提交回复
热议问题