route_distances/distances.py
def route(self, orig_long, orig_lat, dest_long, dest_lat, mode = "walk",
              departure_time = None):
        """ Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object. From the Google Maps
                API Python client docs:

                    Specifies the desired time of departure as seconds since
                    midnight, January 1, 1970 UTC. The departure time may be
                    specified by Google Maps API for Work customers to receive
                    trip duration considering current traffic conditions. The
                    departure_time must be set to within a few minutes of the
                    current time.

                If this is specified, then the traffic-adjusted travel time is
                returned. The client must be authorized with a client ID and
                client secret instead of an API key for this to work.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        """

        self.rate_limit()

        if (departure_time):

            self.log("Sending live traffic-adjusted request to Google")
            result = self.gmaps.distance_matrix(
                origins = (orig_lat, orig_long),
                destinations = (dest_lat, dest_long),
                units = "metric",
                mode = self.map_mode(mode),
                departure_time = departure_time
            )

        else:

            self.log("Sending request to Google")
            result = self.gmaps.distance_matrix(
                origins = (orig_lat, orig_long),
                destinations = (dest_lat, dest_long),
                units = "metric",
                mode = self.map_mode(mode)
            )

        self.log("Response: %s" % result)
        if (result["status"] == "OK"):
            return {
                "duration": result["rows"][0]["elements"][0]["duration"]["value"],
                "distance": result["rows"][0]["elements"][0]["distance"]["value"],
                "response": result
            }

        return False
 Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object. From the Google Maps
                API Python client docs:

                    Specifies the desired time of departure as seconds since
                    midnight, January 1, 1970 UTC. The departure time may be
                    specified by Google Maps API for Work customers to receive
                    trip duration considering current traffic conditions. The
                    departure_time must be set to within a few minutes of the
                    current time.

                If this is specified, then the traffic-adjusted travel time is
                returned. The client must be authorized with a client ID and
                client secret instead of an API key for this to work.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        
Routes the distance between two coordinates
Routes the distance between two coordinates
def route(self, orig_long, orig_lat, dest_long, dest_lat, mode = "walk",
              departure_time = None):
        self.rate_limit()
        if (departure_time):
            self.log("Sending live traffic-adjusted request to Google")
            result = self.gmaps.distance_matrix(
                origins = (orig_lat, orig_long),
                destinations = (dest_lat, dest_long),
                units = "metric",
                mode = self.map_mode(mode),
                departure_time = departure_time
            )
        else:
            self.log("Sending request to Google")
            result = self.gmaps.distance_matrix(
                origins = (orig_lat, orig_long),
                destinations = (dest_lat, dest_long),
                units = "metric",
                mode = self.map_mode(mode)
            )
        self.log("Response: %s" % result)
        if (result["status"] == "OK"):
            return {
                "duration": result["rows"][0]["elements"][0]["duration"]["value"],
                "distance": result["rows"][0]["elements"][0]["distance"]["value"],
                "response": result
            }
        return False
def route ( self , orig_long , orig_lat , dest_long , dest_lat , mode = "walk" , departure_time = None ) : self . rate_limit ( ) if ( departure_time ) : self . log ( "Sending live traffic-adjusted request to Google" ) result = self . gmaps . distance_matrix ( origins = ( orig_lat , orig_long ) , destinations = ( dest_lat , dest_long ) , units = "metric" , mode = self . map_mode ( mode ) , departure_time = departure_time ) else : self . log ( "Sending request to Google" ) result = self . gmaps . distance_matrix ( origins = ( orig_lat , orig_long ) , destinations = ( dest_lat , dest_long ) , units = "metric" , mode = self . map_mode ( mode ) ) self . log ( "Response: %s" % result ) if ( result [ "status" ] == "OK" ) : return { "duration" : result [ "rows" ] [ 0 ] [ "elements" ] [ 0 ] [ "duration" ] [ "value" ] , "distance" : result [ "rows" ] [ 0 ] [ "elements" ] [ 0 ] [ "distance" ] [ "value" ] , "response" : result } return False
Routes the distance between two coordinates
Routes the distance between two coordinates
""" Routes the distance between two coordinates

        Args:
            orig_long: The origin longitude.
            orig_lat: The origin latitude.
            dest_long: The destination longitude.
            dest_lat: The destination latitude.
            mode: A key of the self.mode_map dictionary that will be remapped to
                a different string and passed to the API.
            departure_time: A datetime.datetime object. From the Google Maps
                API Python client docs:

                    Specifies the desired time of departure as seconds since
                    midnight, January 1, 1970 UTC. The departure time may be
                    specified by Google Maps API for Work customers to receive
                    trip duration considering current traffic conditions. The
                    departure_time must be set to within a few minutes of the
                    current time.

                If this is specified, then the traffic-adjusted travel time is
                returned. The client must be authorized with a client ID and
                client secret instead of an API key for this to work.

        Returns:
            A dictionary containing the total duration in the "duration" key and
                the total distance in the "distance" key if there are no errors;
                False if there are errors. Distance is in meters; duration is in
                seconds.
        """
A dictionary containing the total duration in the "duration" key and
the total distance in the "distance" key if there are no errors;
False if there are errors. Distance is in meters; duration is in
seconds.
A dictionary containing the total duration in the " duration " key and the total distance in the " distance " key if there are no errors ; False if there are errors . Distance is in meters ; duration is in seconds .
self
orig_long
The origin longitude.
The origin longitude .
orig_lat
The origin latitude.
The origin latitude .
dest_long
The destination longitude.
The destination longitude .
dest_lat
The destination latitude.
The destination latitude .
mode
A key of the self.mode_map dictionary that will be remapped to
a different string and passed to the API.
A key of the self . mode_map dictionary that will be remapped to a different string and passed to the API .
departure_time
A datetime.datetime object. From the Google Maps
API Python client docs.

Specifies the desired time of departure as seconds since
midnight, January 1, 1970 UTC. The departure time may be
specified by Google Maps API for Work customers to receive
trip duration considering current traffic conditions. The
departure_time must be set to within a few minutes of the
current time.

If this is specified, then the traffic-adjusted travel time is
returned. The client must be authorized with a client ID and
client secret instead of an API key for this to work.
A datetime . datetime object . From the Google Maps API Python client docs . Specifies the desired time of departure as seconds since midnight January 1 1970 UTC . The departure time may be specified by Google Maps API for Work customers to receive trip duration considering current traffic conditions . The departure_time must be set to within a few minutes of the current time . If this is specified then the traffic - adjusted travel time is returned . The client must be authorized with a client ID and client secret instead of an API key for this to work .