【问题标题】:mapbox-navigation-android add waypointsmapbox-navigation-android 添加航点
【发布时间】:2018-01-24 10:15:36
【问题描述】:

我搜索以将航路点添加到我的旅程中。

https://github.com/mapbox/mapbox-navigation-android/blob/master/app/src/main/java/com/mapbox/services/android/navigation/testapp/activity/WaypointNavigationActivity.java

在此示例中,下一个航点是在旅程结束时添加的。我想在同一旅程中添加所有积分。你有什么想法吗?

【问题讨论】:

  • 看看this repo。

标签: android navigation mapbox mapbox-android


【解决方案1】:

您可以在使用NavigationRoute 提出新路线请求时添加航点。

在我们的文档https://www.mapbox.com/android-docs/navigation/overview/ 中,查看4. Requesting a route 部分,您会找到如何执行此操作的示例。

NavigationRoute.Builder builder = NavigationRoute.builder()
  .accessToken(Mapbox.getAccessToken())
  .origin(origin)
  .destination(destination);

for (Position waypoint : waypoints) {
  builder.addWaypoint(waypoint);
}

builder.build();

【讨论】:

  • 这个方法只需要一个路点,这是2路点的输出{ "message": "坐标太多;最大坐标数为3。", "code": "InvalidInput" }
  • @SushantGarg 这可能是因为您正在使用驾驶交通配置文件(最多 3 个航点)。您可以切换到多达 25 个航点的驾驶模式。 docs.mapbox.com/api/navigation/#directions
  • @SushantGarg 非常感谢!你的回答帮了我:) 对于Android SDK,用户必须在profile 方法中使用DirectionsCriteria.DRIVING
【解决方案2】:

试试这个...使用谷歌地图

       StringBuilder sb_latlangdrive = new StringBuilder();
           for (int i = 0; i < arrayList.size(); i++) {
                String split[] = arrayList.get(i).split(",");
                sb_latlangdrive.append(split[0] + "," + split[1] + "|");
             }
             String split[] = arrayList.get(0).split(",");
             String split_endlocaiton[] = arrayList.get(arrayList.size() - 1).split(",");
             Uri gmmIntentUri = Uri.parse("https://www.google.com/maps/dir/?api=1&origin=" + split[0] + "," + split[1] + "&destination=" + split_endlocaiton[0] + "," + split_endlocaiton[1] + "&waypoints=" + sb_latlangdrive.toString() + "&travelmode=driving");
             Intent intent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
             intent.setPackage("com.google.android.apps.maps");
             try {
                   startActivity(intent);
             } catch (ActivityNotFoundException ex) {
               try {
                     Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
                     startActivity(unrestrictedIntent);
                   } catch (ActivityNotFoundException innerEx) {
                      Toast.makeText(TrackingTesting.this, "Please install a maps application", Toast.LENGTH_LONG).show();
                 }
             }

参考见doc here

【讨论】:

  • 好的,但我想在导航模式下使用 MapBox Android。
  • @Gowthaman,感谢您在这里提供的帮助,但这是一个非常不相关的问题答案,问题是关于 Mapbox。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-09-02
  • 2016-03-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-21
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多