Launching Google Maps Directions via an intent on Android

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

    A nice kotlin solution, using the latest cross-platform answer mentioned by lakshman sai...

    No unnecessary Uri.toString and the Uri.parse though, this answer clean and minimal:

     val intentUri = Uri.Builder().apply {
          scheme("https")
          authority("www.google.com")
          appendPath("maps")
          appendPath("dir")
          appendPath("")
          appendQueryParameter("api", "1")
          appendQueryParameter("destination", "${yourLocation.latitude},${yourLocation.longitude}")
     }.build()
     startActivity(Intent(Intent.ACTION_VIEW).apply {
          data = intentUri
     })
    

提交回复
热议问题