我的应用程序需要显示从A到B的Google Maps方向,但我不想将Google Maps放到我的应用程序中-相反,我想使用Intent启动它。这个是可能的吗?如果是,是如何实现的?
发布于 2015-03-07 15:01:39
您可以尝试使用Intent.setClassName
方法打开内置应用程序Android Maps。
Intent i = new Intent(Intent.ACTION_VIEW,Uri.parse("geo:37.827500,-122.481670"));
i.setClassName("com.google.android.apps.maps",
"com.google.android.maps.MapsActivity");
startActivity(i);
发布于 2017-05-16 15:21:05
对于多个路点,也可以使用下面的方法。
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/dir/48.8276261,2.3350114/48.8476794,2.340595/48.8550395,2.300022/48.8417122,2.3028844"));
startActivity(intent);
第一组坐标是您的起始位置。接下来的都是路点,绘制的路线都经过了。
只需通过在末尾连接"/latitude,经度“来添加路点即可。根据google docs的说法,显然有23个路点的限制。不确定这是否也适用于Android。
发布于 2020-04-21 16:07:57
一个很好的kotlin解决方案,使用了lakshman提到的最新的跨平台答案。
虽然没有不必要的Uri.toString和Uri.parse,但这个答案简洁而简洁:
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
})
https://stackoverflow.com/questions/2662531
复制相似问题