I'm developing a simple application of public trasport, with buses and stops. The buses doesn't have gps. Every bus stop is an object of type location.
How can I plan the route of every buses along the streets respecting road signs(the distance between 2 bus stop) and how can I go the a bus stop by walk?
Because using
location1.distanceBetweenTo(location2)
return the distance as the crow flies.
Is it possible to have also the time between 2 location(bus stop)? Because the bus company doesn't have a plan of each stops and time , but the generics time from the departure stop and the arrival stop.
I have already create the map, getting the api key on the google console and I suppose that each bus stop can be represented by a marker.
--EDIT--
This code seems to be working but how create the result?
final JSONObject json = new JSONObject(result);
JSONArray routeArray = json.getJSONArray("routes");
JSONObject routes = routeArray.getJSONObject(0);
JSONArray newTempARr = routes.getJSONArray("legs");
JSONObject newDisTimeOb = newTempARr.getJSONObject(0);
JSONObject distOb = newDisTimeOb.getJSONObject("distance");
JSONObject timeOb = newDisTimeOb.getJSONObject("duration");
Log.i("Distance :", distOb.getString("text"));
Log.i("Time :", timeOb.getString("text"));
I have used some jsonParser but nothing working. How create it starting with latitude and longitude ?
I have already tried in this way.
String url =" https://maps.googleapis.com/maps/api/directions/json?origin=41.221298,16.286054&destination=41.217956,16.2988407&key="my api key"
This string is passed to
private String getResponseText(String stringUrl) throws IOException
{
StringBuilder response = new StringBuilder();
URL url = new URL(stringUrl);
HttpURLConnection httpconn = (HttpURLConnection)url.openConnection();
if (httpconn.getResponseCode() == HttpURLConnection.HTTP_OK)
{
BufferedReader input = new BufferedReader(new InputStreamReader(httpconn.getInputStream()),8192);
String strLine = null;
while ((strLine = input.readLine()) != null)
{
response.append(strLine);
}
input.close();
}
return response.toString();
}
but nothing changes.