Hi Guys i am working on Google maps Implementation.
I am trying to draw path via google maps.I have button to start and stop the GPS, basically to get Lat and Long values.
Eg : i may get 10 lat and long values and i store them in ArrayList.
Now i am trying to draw a path with the above list of lat and long, If i use the Google maps API then i need to send only start and end points of my ArrayList and then it draws/renders on the map,but its not the way i wanted.
I wanted to draw the path along the list of lat and long values (10 values).The reason is google just gives us the path from start to end but it might not be the way/route in which the user has travelled.
How can we do this ?
Below is what i am doing :
private String getMapsApiDirectionsUrl(LatLng source, LatLng destination, String mode) {
// Origin of route
String str_origin = "origin=" + source.latitude + "," + source.longitude;
// Destination of route
String str_dest = "destination=" + destination.latitude + "," + destination.longitude;
// Sensor enabled
String sensor = "sensor=false";
// Building the parameters to the web service
String parameters = str_origin + "&" + str_dest + "&" + sensor + "&" + mode + "&alternatives=true";
// Output format
String output = "json";
// Building the url to the web service
String url = "https://maps.googleapis.com/maps/api/directions/" + output + "?" + parameters;
Log.e(TAG, " " + url);
return url;
}
private class ReadTask extends AsyncTask<String, Void, String> {
@Override
protected String doInBackground(String... url) {
String data = "";
try {
HttpConnection http = new HttpConnection();
data = http.readUrl(url[0]);
} catch (Exception e) {
Log.d("Background Task", e.toString());
}
return data;
}
@Override
protected void onPostExecute(String result) {
super.onPostExecute(result);
new ParserTask().execute(result);
}
}
private class ParserTask extends
AsyncTask<String, Integer, List<List<HashMap<String, String>>>> {
@Override
protected List<List<HashMap<String, String>>> doInBackground(
String... jsonData) {
JSONObject jObject;
List<List<HashMap<String, String>>> routes = null;
try {
jObject = new JSONObject(jsonData[0]);
PathJSONParser parser = new PathJSONParser();
routes = parser.parse(jObject);
} catch (Exception e) {
e.printStackTrace();
}
return routes;
}
@Override
protected void onPostExecute(List<List<HashMap<String, String>>> routes) {
task.callBack(routes);
}
}
EDIT
i am doing exactly the way its shown here, but what happens is based on the start and end values Google maps APi V2 gives me the route but that might not be the route that user has travelled, as he has might have visited some places in between the start and end.