android - 在 Mapbox Android 中添加坐标
问题描述
我正在使用mapbox android,我正在尝试在起点和目的地之间添加多个航点。但是在添加一个航点后,当它添加另一个航点后,会出现异常“s 坐标太多;最大坐标数为3。”
我只想在两点之间添加多个航点并在mapbox android中的这些线上绘制路线。
[pastbin 链接]:https ://paste.ubuntu.com/p/PKMQzFyzVb/
我的路线绘制功能 -->
{
private void getRouteWithWaypoint(Point origin, Point destination, List<Point> wayPoints) {
assert Mapbox.getAccessToken() != null;
NavigationRoute.Builder builder = NavigationRoute.builder(getActivity())
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination);
if (wayPoints != null) {
for (Point point : wayPoints) {
builder.addWaypoint(point);
}
}
builder.build().getRoute(new Callback<DirectionsResponse>() {
@Override
public void onResponse(@NonNull Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
Log.e(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right user and access token.");
return;
} else if (response.body().routes().size() < 1) {
Log.e(TAG, "No routes found");
return;
}
currentRoute = response.body().routes().get(0);
if (navigationMapRoute != null) {
navigationMapRoute.removeRoute();
} else {
navigationMapRoute = new NavigationMapRoute(null, mapView, map, R.style.NavigationMapRoute);
}
navigationMapRoute.addRoute(currentRoute);
}
@SuppressLint("TimberArgCount")
@Override
public void onFailure(Call<DirectionsResponse> call, Throwable t) {
Timber.e(t, "Error: %s");
}
});
}}
解决方案
请求路由的默认配置文件是DirectionsCriteria.ProfileCriteria.PROFILE_DRIVING_TRAFFIC
此配置文件仅允许起点和终点之间的 1 个航路点。如果您想使用超过 1 个航点,只需使用PROFILE_DRIVING
(我认为这最多允许 25 个航点)。
像这样:
NavigationRoute.Builder builder = NavigationRoute.builder(getActivity())
.accessToken(Mapbox.getAccessToken())
.origin(origin)
.destination(destination)
.profile(DirectionsCriteria.ProfileCriteria.PROFILE_DRIVING);
if (wayPoints != null) {
for (Point point : wayPoints) {
builder.addWaypoint(point);
}
}
推荐阅读
- r - 将函数应用于列表中所有有意义的组合并以矩阵格式保存
- javascript - 如何使用 nouislider 中的滑块过滤 Leaflet.js 上的聚集标记
- apache - 使用 Apache Web 服务器在代理通行证下 TURN 服务器
- javascript - React Native - 如何在不使用 React Redux 的情况下从其他组件传递图像
- python - 如何在 cartopy 地图上创建动态 matplotlib 图?
- ruby-on-rails - rails db:setup rails 中止!nil:NilClass 的未定义方法 `[]' 我正在使用 Postgresql 和 rails 5
- ruby-on-rails - ruby 和 rails 更新后未定义的方法“delete_if”
- python - 如何在 QEvent 中捕获 NonClientAreaMouseMove 事件
- jquery - 有没有办法改变
插件通过 jquery 生成的标签? - sharepoint - SharePoint 列表是否能够按用户或状态字段控制字段编辑访问?