Reputation: 149
i would like to use the roads api to get the distance of my currentlocation and add the list of Latlng in onLocationChanged and to snap a set of coordinates (approx 100~200 points) to roads and that will return a json to get the accurate distance of driving.
-- i got a problem with path parameters the latitude and longitude is not populating in which join by this "|" but i got an error like. ---This is my url
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);
}
});
}
--Error snaptoroads error:400 message:path.
Upvotes: 0
Views: 1150
Reputation: 11
Status code 400 is due to a invalid request.Roads API takes in at most 100 points , try decreasing your points.
Upvotes: 1