我想使用道路api来获取我当前位置的距离,并在onLocationChanged中添加Latlng列表,并将一组坐标(大约100~200点)捕捉到道路,这将返回一个json以获取准确的驾驶距离。
- 我遇到了路径参数的问题,纬度和经度没有填充在这个" |"但是我得到了一个错误。 ---这是我的网址
protected String getSnapUrl(List<LatLng> pat_value) {
String str_path = null;
for (int x = 0; x < pat_value.size(); x++) {
str_path = "path=" + pat_value.get(x).latitude + "," + pat_value.get(x).longitude + "|";
Log.e("path", "" + pat_value.get(x).latitude + "-" + pat_value.get(x).longitude);
}
String str_interpolate = "interpolate=true";
String key = "key=google key";
String parameters = str_path + "&" + str_interpolate + "&" + key;
String output = "snapToRoads";
String url = output + "?" + parameters;
return url;
}
protected void snapToRoad() {
SnapToRoadAsyncHttpClient.get(getSnapUrl(path), null, new JsonHttpResponseHandler() {
@Override
public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
super.onSuccess(statusCode, headers, response);
Log.e("snapToRoad", "" + response);
}
@Override
public void onFailure(int statusCode, Header[] headers, Throwable throwable, JSONObject errorResponse) {
super.onFailure(statusCode, headers, throwable, errorResponse);
Log.e("snapToRoadFail", "" + errorResponse + throwable);
}
@Override
public void onFailure(int statusCode, Header[] headers, String responseString, Throwable throwable) {
super.onFailure(statusCode, headers, responseString, throwable);
Log.e("snapToRoadFail", "" + responseString + throwable);
}
});
}
- 错误snaptoroads错误:400消息:路径。
答案 0 :(得分:1)
状态代码400是由于无效的请求。路由API最多需要100个点,尝试减少您的积分。