android - Intent 使用 Google 导航获取具有多个航路点的行程

标签 android google-maps android-intent google-maps-urls

我想知道,是否可以在“Google 导航”(Google map 导航)中放置几个​​“检查点”,查询遵循以下语法:"google.navigation:q=44.871709,-0.505704 ....”

如果可能的话,分开两点的语法是什么?

有一点它有效,例如:"google.navigation:q=44.871709,-0.505704"

但我会放几个检查点,例如:

 LatLng point1 = new LatLng(44.871709,-0.505704);
 LatLng point2 = new LatLng(43.572665,3.871447);                    
 Intent(android.content.Intent.ACTION_VIEW,Uri.parse("google.navigation:q="+
 point1.latitude+","+point1.longitude+";"+ point2.latitude+","+point2.longitude));  

我读过其他问题,他们说要使用这种语法:

"http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447"

使用上述解决方案,“Google Navigation”不会自动启动,我们必须选择一个应用程序“Google Maps”,然后单击 Itinerary(在屏幕顶部)以启动“Google Navigation”。 如果可能的话,我想避免它。

最佳答案

这是一种抑制对话框并直接转到 map 的方法。

String uri = "http://maps.google.com/maps?saddr="+"44.871709,-0.505704"+"&daddr="+"43.572665,3.871447";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

如果您还有问题,请告诉我。

更新

截至 2017 年 5 月,有一种更好的方法,即 Google Maps URLs API

https://developers.google.com/maps/documentation/urls/guide

使用此 API,您可以构建包含起点、目的地和航路点的 URL,并将其传递给 Intent

String uri = "https://www.google.com/maps/dir/?api=1&origin=Madrid,Spain&destination=Barcelona,Spain&waypoints=Zaragoza,Spain%7CHuesca,Spain&travelmode=driving&dir_action=navigate";
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(uri));
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent); 

关于android - Intent 使用 Google 导航获取具有多个航路点的行程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16717609/

相关文章:

android - 在有 Intent 地启动 Activity 之前清除 Activity 堆栈

android - 使用 rxjava 我无法从主线程进行改造

Android:将数据从数据库绑定(bind)到 ListView

ios - 反转 GMSMutablePath 数组

javascript - Google Maps API:跨域读取阻止(CORB)阻止了跨源响应

java - 单击单选按钮时如何 toast 消息

android - SQlite触发器执行问题

java - 除了使用Java语言的getString(R.string.idString)之外,还有其他方法可以获取Android字符串资源的值吗?

javascript - 编码非拉丁字符谷歌地图标记信息

java - 从 Activity 返回结果