// 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 List<Event> GetEvents(string days) { String apiAddress = "http://api.football-data.org/v1/soccerseasons/398/fixtures"; string apiAddressWithParams = apiAddress + urlParameters(days); ApiCaller api = new ApiCaller(); String jsonString = api.GET(apiAddressWithParams); // calls the API and gets a String // convert the string to a list of events – see below for this method JSONparser jsonParser = new JSONparser(); return jsonParser.GetInfoFromWholeFootballDataComJSONstring(jsonString); }
public List <Event> GetEvents(string days) { String apiAddress = "http://api.football-data.org/v1/soccerseasons/398/fixtures"; string apiAddressWithParams = apiAddress + urlParameters(days); ApiCaller api = new ApiCaller(); String jsonString = api.GET(apiAddressWithParams); // calls the API and gets a String // convert the string to a list of events – see below for this method JSONparser jsonParser = new JSONparser(); return(jsonParser.GetInfoFromWholeFootballDataComJSONstring(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); }
//adding in the events to the parameter public List<Event> distancefromLocation(List<Event> events, string location, string travelmode) { ApiCaller api = new ApiCaller(); JSONparser jsonParser = new JSONparser(); // calls the API and gets a String //String jsonString = api.GET(apiAddress + urlParameters(location)); //PS 2/12/2015: commented this out as it's in the for loop now // convert the string to a list of events – see below for this method //List<Event> events = jsonParser.GetInfoFromWholeFootballDataComJSONstring(jsonString); // right, so: location is the current location of the user // so we're going to go through each event in the 'events' list and work out the location from the event to the current location foreach(Event currentEvent in events) { //currentEvent.distance = getDistanceFromAtoB(location, currentEvent.locationLatitude, currentEvent.locationLongitude); PopulateEventWithDistances(currentEvent, location, travelmode); } // returns the events return events; }
public List <Event> distancefromLocation(List <Event> events, string location, string travelmode) //adding in the events to the parameter { ApiCaller api = new ApiCaller(); JSONparser jsonParser = new JSONparser(); // calls the API and gets a String //String jsonString = api.GET(apiAddress + urlParameters(location)); //PS 2/12/2015: commented this out as it's in the for loop now // convert the string to a list of events – see below for this method //List<Event> events = jsonParser.GetInfoFromWholeFootballDataComJSONstring(jsonString); // right, so: location is the current location of the user // so we're going to go through each event in the 'events' list and work out the location from the event to the current location foreach (Event currentEvent in events) { //currentEvent.distance = getDistanceFromAtoB(location, currentEvent.locationLatitude, currentEvent.locationLongitude); PopulateEventWithDistances(currentEvent, location, travelmode); } // returns the events return(events); }
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; }