예제 #1
0
        // 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);
        }
예제 #2
0
        // 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));
        }
예제 #3
0
        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);
        }
예제 #4
0
        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;
        }