如何通过google map api最新版本(google play service 8.3)绘制从当前位置到目的地的行车路线

时间:2015-12-04 03:38:04

标签: android google-maps

之前我使用Android: How to draw route directions google maps API V2 from current location to destination中的GmapV2。但现在这不起作用我得到关于那个班级的错误。如何修复该课程?

1 个答案:

答案 0 :(得分:0)

此代码将绘制从原点到目的地的行。

@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
    Log.d("Status", "Success");
    Log.d("Direction", "" + direction);
    mMap.addMarker(new MarkerOptions().position(origin));
    mMap.addMarker(new MarkerOptions().position(destination));
    if (waypoints != null){
        for (int i = 0; i < waypoints.size(); i++){
            mMap.addMarker(new MarkerOptions().position(waypoints.get(i)));
        }
    }

    ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
    mMap.addPolyline(DirectionConverter.createPolyline(this, directionPositionList, 5, Color.BLUE));

    Log.d("Status", "Success 2");
    showRoute.setVisibility(View.GONE);
}