android中两个标记之间的路由

时间:2019-01-08 06:41:03

标签: android google-maps routes google-maps-direction-api

我正在尝试开发一个android应用程序。我正在使用direction API在两个route之间绘制marker。我正在使用以下代码绘制route。当我第一次运行应用程序时,它运行良好。但第二次direction api显示OVER_QUERY_LIMIT

        GoogleDirection.withServerKey("AIzaSyCua7p46J7YKwxS99H5orm2Ikn8OltIcF0")
                .from(currentLatLng)
                .to(desLatLng)
                .transportMode(TransportMode.DRIVING)
                .execute(this);




@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
    Toast.makeText(getApplicationContext(),"Success with status : " +direction.getStatus(),Toast.LENGTH_LONG).show();
    if (direction.isOK()) {

        Route route = direction.getRouteList().get(0);
        int legCount = route.getLegList().size();
        for (int index = 0; index < legCount; index++) {
            Leg leg = route.getLegList().get(index);
            //mMap.addMarker(new MarkerOptions().position(leg.getStartLocation().getCoordination()));
            if (index == legCount - 1) {
               // mMap.addMarker(new MarkerOptions().position(leg.getEndLocation().getCoordination()));
            }
            List<Step> stepList = leg.getStepList();
            ArrayList<PolylineOptions> polylineOptionList = DirectionConverter.createTransitPolyline(this, stepList,
                    5, Color.BLACK, 3, Color.BLUE);
            for (PolylineOptions polylineOption : polylineOptionList) {
                mMap.addPolyline(polylineOption);
            }
        }
        setCameraWithCoordinationBounds(route);
    } else {
        Toast.makeText(getApplicationContext(),direction.getStatus(),Toast.LENGTH_LONG).show();
    }
}

@Override
public void onDirectionFailure(Throwable t) {
    Toast.makeText(getApplicationContext(),t.getMessage(),Toast.LENGTH_LONG).show();
}

1 个答案:

答案 0 :(得分:1)

由于没有结算帐户,您可能会看到“ OVER_QUERY_LIMIT”,要使用Google Direction API,您必须在开发者控制台中设置结算帐户。