【问题标题】:Update direction path on Google Maps in driving mode在驾驶模式下更新谷歌地图上的方向路径
【发布时间】:2019-04-30 05:42:09
【问题描述】:

我正在使用 Google 地图,现在我通过使用带有移动标记动画的 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 获取方向。我不想一次又一次地调用它,因为上一行也有一个新的。

有人能帮帮我吗???

【问题讨论】:

    标签: android google-maps-api-3 google-polyline google-directions-api


    【解决方案1】:

    请先将此功能添加到活动中

      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());
    

    【讨论】:

    • 嗨 Mohamad Mehdi,感谢您的回复。 setOnLocationFoundListener() 在这里做什么?当我们移动到另一条路径时它会自动调用吗?我没有得到这种方法。它显示错误。
    猜你喜欢
    • 2012-11-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-05-22
    • 2012-12-26
    • 1970-01-01
    相关资源
    最近更新 更多