How to open standard Google Map application from my application?

后端 未结 9 953
星月不相逢
星月不相逢 2020-11-28 01:09

Once user presses button in my application, I would like to open standard Google Map application and to show particular location. How can I do it? (without using com.g

9条回答
  •  悲&欢浪女
    2020-11-28 01:55

    This is written in Kotlin, it will open the maps app if it's found and place the point and let you start the trip:

      val gmmIntentUri = Uri.parse("http://maps.google.com/maps?daddr=" + adapter.getItemAt(position).latitud + "," + adapter.getItemAt(position).longitud)
            val mapIntent = Intent(Intent.ACTION_VIEW, gmmIntentUri)
            mapIntent.setPackage("com.google.android.apps.maps")
            if (mapIntent.resolveActivity(requireActivity().packageManager) != null) {
                startActivity(mapIntent)
            }
    

    Replace requireActivity() with your Context.

提交回复
热议问题