I am building a personal project to familiarise myself with API calling etc.
I have the following function:
public void calculateDistance(House house) {
DirectionsApiRequest apiRequest = DirectionsApi.newRequest(geoApiContext);
apiRequest.origin(new LatLng(house.getLat(), house.getLon()));
apiRequest.destination(biminghamInternationStationLonLat);
apiRequest.mode(TravelMode.TRANSIT);
apiRequest.setCallback(new com.google.maps.PendingResult.Callback<DirectionsResult>() {
@Override
public void onResult(DirectionsResult result) {
DirectionsRoute[] routes = result.routes;
System.out.println("Printing out the results for " + house.getUrlListing());
for(int i =0 ; i < routes.length; i++)
{
DirectionsRoute route = routes[i];
System.out.println(route);
}
}
@Override
public void onFailure(Throwable e) {
}
});
}
What this function does is gets the latitude and longitude of the custom House object I am providing, and essentially finds how long it takes to reach birmingham international station via public transport (hence the TRANSIT mode in the apiRequest).
But I'm not sure if I am using it correctly? When I go on google maps website and check how long it'll take for me to get to birmingham international station from the location of the house; I get results varying from 30-35 mins, okay. But when I try calling the above code it prints the following:
[DirectionsRoute: "", 1 legs, waypointOrder=[], bounds=[52.48039080,-1.72493200, 52.45082300,-1.78392750], 1 warnings]
I'm not sure how I can get the time it takes via public transport from the api. I am using the Directions API.. not sure if im using the wrong API but when looking at what API to use, this was described what I needed..