android - android中两个标记之间的路由

标签 android google-maps routes google-directions-api

我正在尝试开发一个安卓应用程序。我正在使用 direction API 在两个 marker 之间绘制一条 route。我正在使用下面的代码绘制 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();
}

最佳答案

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

关于android - android中两个标记之间的路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54086453/

相关文章:

android - 以圆形布局显示文本

android - 如何使用 adjustPan 保持工具栏可见?

reactjs - 在 InfoWindow 内容中使用 React 组件

java - 如何使用 Play 2.0 路由绑定(bind) Double 参数

php - 通过 PHP + JSON 从 MySql 获取状态

android - Gradle Sonar 运行者 : fail build on failed Quality Gate

php - 谷歌地图 - 查找给定半径内的所有标记 Javascript/Php

java - 如何在 Android 应用程序中显示源和目的地的路径并在应用程序中导航用户

Asp.Net MVC - 重载操作方法

C++ windows32 winsock UDP路由?