// new method . Uses the GoogleAPI to work out the distance from A to B //might want to swap this, so that it gets the location and time taken, in which case you'll want to pass in the object instead of locationB... //public int getDistanceFromAtoB(String locationA, String locationB) public int getDistanceFromAtoB(String locationA, String locationBLatitude, String locationBLongitude, string travelmode) { // setting up the variables ApiCaller api = new ApiCaller(); JSONparserdistances jsonParser = new JSONparserdistances(); // Changed this too the new JSON parser String apiAddress = "https://maps.googleapis.com/maps/api/distancematrix/json"; // calling the api String jsonString = api.GET(apiAddress + "?" + origin(locationA) + "&" + destination(locationBLatitude, locationBLongitude) + "&" + mode(travelmode) + "&" + apiKey()); // parse and return the result return jsonParser.extractDistanceFromGoogleMapsJsonString(jsonString); }
// new method . Uses the GoogleAPI to work out the distance from A to B //might want to swap this, so that it gets the location and time taken, in which case you'll want to pass in the object instead of locationB... //public int getDistanceFromAtoB(String locationA, String locationB) public int getDistanceFromAtoB(String locationA, String locationBLatitude, String locationBLongitude, string travelmode) { // setting up the variables ApiCaller api = new ApiCaller(); JSONparserdistances jsonParser = new JSONparserdistances(); // Changed this too the new JSON parser String apiAddress = "https://maps.googleapis.com/maps/api/distancematrix/json"; // calling the api String jsonString = api.GET(apiAddress + "?" + origin(locationA) + "&" + destination(locationBLatitude, locationBLongitude) + "&" + mode(travelmode) + "&" + apiKey()); // parse and return the result return(jsonParser.extractDistanceFromGoogleMapsJsonString(jsonString)); }
public Event PopulateEventWithDistances(Event currentEvent, String locationA, string travelmode) { // setting up the variables ApiCaller api = new ApiCaller(); JSONparserdistances jsonParser = new JSONparserdistances(); // Changed this too the new JSON parser String apiAddress = "https://maps.googleapis.com/maps/api/distancematrix/json"; String addressToCall = apiAddress + "?" + origin(locationA) + "&" + destination(currentEvent.locationLatitude, currentEvent.locationLongitude) + "&" + mode(travelmode) + "&" + apiKey(); // calling the api String jsonString = api.GET(addressToCall); currentEvent.distance = jsonParser.extractDistanceFromGoogleMapsJsonString(jsonString); currentEvent.duration = jsonParser.extractTimeTakenFromGoogleMapsJsonString(jsonString); currentEvent.durationFriendly = jsonParser.extractFriendlyTimeTakenFromGoogleMapsJsonString(jsonString); currentEvent.distanceFriendly = convertFromMetersToMiles(currentEvent.distance); return(currentEvent); }
public Event PopulateEventWithDistances(Event currentEvent, String locationA, string travelmode) { // setting up the variables ApiCaller api = new ApiCaller(); JSONparserdistances jsonParser = new JSONparserdistances(); // Changed this too the new JSON parser String apiAddress = "https://maps.googleapis.com/maps/api/distancematrix/json"; String addressToCall = apiAddress + "?" + origin(locationA) + "&" + destination(currentEvent.locationLatitude, currentEvent.locationLongitude) + "&" + mode(travelmode) + "&" + apiKey(); // calling the api String jsonString = api.GET(addressToCall); currentEvent.distance = jsonParser.extractDistanceFromGoogleMapsJsonString(jsonString); currentEvent.duration = jsonParser.extractTimeTakenFromGoogleMapsJsonString(jsonString); currentEvent.durationFriendly = jsonParser.extractFriendlyTimeTakenFromGoogleMapsJsonString(jsonString); currentEvent.distanceFriendly = convertFromMetersToMiles(currentEvent.distance); return currentEvent; }