我正在使用Google Map,现在我通过使用带有移动标记动画的Google Direction API在当前位置显示一条黑白线。
现在,如果我在开车时更改了路径,那么如何更新从当前位置到目的地的路径。
这是我的代码
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
if (direction.isOK()) {
route = direction.getRouteList().get(0);
ArrayList<LatLng> directionPositionList = route.getLegList().get(0).getDirectionPoint();
mMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 8, Color.BLUE));
} else {
Toast.makeText(DriversActivity.this, direction.getStatus(), Toast.LENGTH_SHORT).show();
}
在OnDirectionSuccess方法中,m获取方向。我不想一次又一次地调用它,因为上一行也有一个新的一行。
有人可以帮我吗?
答案 0 :(得分:0)
请首先将此功能添加到活动中
private void route(AbstractRouting.TravelMode travelMode, final LatLng end) {
this.end = end;
DataShahrManager dataShahrManager = DataShahrManager.getInstance(activity);
if (dataShahrManager.getMyLocation() != null) {
start = new LatLng(dataShahrManager.getMyLocation().getLatitude(),
dataShahrManager.getMyLocation().getLongitude());
if (end != null) {
mapsFragment.getProgressBar().setVisibility(View.VISIBLE);
Routing routing = new Routing.Builder()
.travelMode(travelMode)
.withListener(this)
.alternativeRoutes(false)
.waypoints(start, end)
.language("fa")
.key("your key")
.build();
routing.execute();
}
} else {
mapsFragment.getLocationProgressBar().setVisibility(View.VISIBLE);
mapsFragment.startLocationFinding();
mapsFragment.setUpMyLocationUsingMap();
if (activity != null) {
Toast.makeText(activity, R.string.finding_your_location, Toast.LENGTH_SHORT).show();
}
mapsFragment.setOnLocationFoundListener(() -> route(AbstractRouting.TravelMode.DRIVING, end));
}
} 所以将此行添加到按钮
route(AbstractRouting.TravelMode.DRIVING, businessEntity.getLatLng());