I doing my android project about bus tracker in Uni campus. I need to draw a route from a bus stop to another bus stop and until back to origin bus stop.(There is about 20 bus stop in my Uni, need to draw route to let first user know the route of buses).
I managed to draw a path by following this tutorial here
In another tutorial , I found a blog which teaching draw path on google maps in 3 location. The sample code is
private static final LatLng LOWER_MANHATTAN = new LatLng(40.722543,-73.998585);
private static final LatLng BROOKLYN_BRIDGE = new LatLng(40.7057, -73.9964);
private static final LatLng WALL_STREET = new LatLng(40.7064, -74.0094);
private String getMapsApiDirectionsUrl() {
String waypoints = "waypoints=optimize:true|"
+ LOWER_MANHATTAN.latitude + "," + LOWER_MANHATTAN.longitude
+ "|" + "|" + BROOKLYN_BRIDGE.latitude + ","
+ BROOKLYN_BRIDGE.longitude + "|" + WALL_STREET.latitude + ","
+ WALL_STREET.longitude;
String sensor = "sensor=false";
String params = waypoints + "&" + sensor;
String output = "json";
String url = "https://maps.googleapis.com/maps/api/directions/"
+ output + "?" + params;
return url;
}
but I got an error which are:
java.io.FileNotFoundException: https://maps.googleapis.com/maps/api/directions/json?waypoints=optimize:true|2.920114,101.775244||2.919726,101.771172|2.92234,101.769628&sensor=false
E/Background Task: java.lang.NullPointerException
E/ParserTask: errororg.json.JSONException: End of input at character 0 of
The tutorial of the blog is same with the link. Just different in
String waypoints = "waypoints=optimize:true|"
+ LOWER_MANHATTAN.latitude + "," + LOWER_MANHATTAN.longitude
+ "|" + "|" + BROOKLYN_BRIDGE.latitude + ","
+ BROOKLYN_BRIDGE.longitude + "|" + WALL_STREET.latitude + ","
+ WALL_STREET.longitude;
and
/ Origin of route
String str_origin = "origin="+origin.latitude+","+origin.longitude;
// Destination of route
String str_dest = "destination="+dest.latitude+","+dest.longitude;
Can anyone give me some tutorial or guidance in draw path in multiple markes? Thank in advance!