我正在使用Android地理定位应用,并且我正在使用 com.akexorcist:googledirectionlibrary:1.0.4 库。我曾经使用此代码绘制路线
public void requestDirection(final LatLng origin, final LatLng destination) {
Toast.makeText(getBaseContext(), "Requesting direction, just a moment...", Toast.LENGTH_SHORT).show();
GoogleDirection.withServerKey(SERVER_KEY)
.from(origin)
.to(destination)
.transportMode(TransportMode.DRIVING)
.execute(new DirectionCallback() {
@Override
public void onDirectionSuccess(Direction direction, String rawBody) {
if (direction.isOK()) {
ArrayList<LatLng> directionPositionList = direction.getRouteList().get(0).getLegList().get(0).getDirectionPoint();
if (!colorBlue && !path){
mGoogleMap.addPolyline(DirectionConverter.createPolyline(getApplicationContext(), directionPositionList, 5, Color.RED));
}
else if (colorBlue){
mGoogleMap.addPolyline(DirectionConverter.createPolyline(getApplicationContext(), directionPositionList, 5, Color.BLUE));
colorBlue = false;
}else if (cancelled){
mGoogleMap.addPolyline(DirectionConverter.createPolyline(getApplicationContext(), directionPositionList, 5, Color.GREEN));
cancelled = false;
}
}else Toast.makeText(getBaseContext(), "Route suspicious", Toast.LENGTH_SHORT).show();
}
@Override
public void onDirectionFailure(Throwable t) {
Toast.makeText(getBaseContext(), "An error occured!", Toast.LENGTH_SHORT).show();
}
});
}
但现在我总是收到路由可疑消息。调试后,我注意到 directionPositionList 始终为空,即使原点和目的地都不是。 任何想法我怎样才能解决这个问题?提前致谢
答案 0 :(得分:0)
问题在于Google ServerKey已过期,因此在更改密钥后我能够绘制路径againe。