我正在使用MapBox方向与Android,我试图获取方向,以便稍后在地图上绘制.
但是,我从调用中得到的响应永远不能用作response.body()返回null.
当我调用response.code()时,我得到状态代码422,根据Mapbox API意味着"给定的请求无效.响应的消息密钥将保存无效输入的解释".
response.message()返回字符串"Unknown".
response.errorBody()返回字符串"okhttp3.ResponseBody$1@38fb6f04"
我使用了相同的代码,因为这个堆栈溢出应答应该可行,但事实并非如此.任何帮助,将不胜感激.
继承我的方法:
private void getRoute(Position origin, Position destination) throws ServicesException {
MapboxDirections client = new MapboxDirections.Builder()
.setOrigin(origin)
.setDestination(destination)
.setProfile(DirectionsCriteria.PROFILE_CYCLING)
.setAccessToken("Same access token as the map uses")
.build();
client.enqueueCall(new Callback<DirectionsResponse>() {
@Override
public void onResponse(Call<DirectionsResponse> call, Response<DirectionsResponse> response) {
// You can get the generic HTTP info about the response
Log.d(TAG, "Response code: " + response.code());
if (response.body() == null) {
Log.e(TAG, "No routes found, make sure you set the right …Run Code Online (Sandbox Code Playgroud)