首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >在Android上通过intent推出Google Maps Directions

在Android上通过intent推出Google Maps Directions
EN

Stack Overflow用户
提问于 2010-04-18 22:27:41
回答 10查看 345.5K关注 0票数 422

我的应用程序需要显示从A到B的Google Maps方向,但我不想将Google Maps放到我的应用程序中-相反,我想使用Intent启动它。这个是可能的吗?如果是,是如何实现的?

EN

回答 10

Stack Overflow用户

发布于 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);
票数 8
EN

Stack Overflow用户

发布于 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。

票数 8
EN

Stack Overflow用户

发布于 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
 })
票数 6
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/2662531

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档