route_distances/distances.py
def route(self, from_long, from_lat, to_long, to_lat, mode = "walk",
                  avoid = []):
        """ 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.
            avoid: An array of (long, lat) pairs to be avoided.

        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.
        """

        request_json = {
            "locations": [
                {"lon": from_long, "lat": from_lat},
                {"lon": to_long, "lat": to_lat},
            ],
            "costing": self.map_mode(mode),
            "directions_options": {
                "units": "kilometers"
            }
        }

        if (len(avoid) > 0):
            request_json["avoid_locations"] = [
                {"lat": x[0], "lon": x[1]} for x in avoid
            ]

        self.log("Sending request JSON to %s: %s" % (self.entrypoint,
                                                     request_json))
        response = requests.post(
            "http://%s/route" % self.entrypoint,
            json = request_json,
            timeout = self.timeout
        )
        data = response.content.decode()
        self.log("Response: %s" % data)

        if (response.status_code == 200):
            content = json.loads(data)
            if (not "error" in content):
                return {
                    "distance": content["trip"]["legs"][0]["summary"]["length"] * 1000,
                    "duration": content["trip"]["legs"][0]["summary"]["time"],
                    "response": content
                }

        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.
            avoid: An array of (long, lat) pairs to be avoided.

        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, from_long, from_lat, to_long, to_lat, mode = "walk",
                  avoid = []):
        request_json = {
            "locations": [
                {"lon": from_long, "lat": from_lat},
                {"lon": to_long, "lat": to_lat},
            ],
            "costing": self.map_mode(mode),
            "directions_options": {
                "units": "kilometers"
            }
        }
        if (len(avoid) > 0):
            request_json["avoid_locations"] = [
                {"lat": x[0], "lon": x[1]} for x in avoid
            ]
        self.log("Sending request JSON to %s: %s" % (self.entrypoint,
                                                     request_json))
        response = requests.post(
            "http://%s/route" % self.entrypoint,
            json = request_json,
            timeout = self.timeout
        )
        data = response.content.decode()
        self.log("Response: %s" % data)
        if (response.status_code == 200):
            content = json.loads(data)
            if (not "error" in content):
                return {
                    "distance": content["trip"]["legs"][0]["summary"]["length"] * 1000,
                    "duration": content["trip"]["legs"][0]["summary"]["time"],
                    "response": content
                }
        return False
def route ( self , from_long , from_lat , to_long , to_lat , mode = "walk" , avoid = [ ] ) : request_json = { "locations" : [ { "lon" : from_long , "lat" : from_lat } , { "lon" : to_long , "lat" : to_lat } , ] , "costing" : self . map_mode ( mode ) , "directions_options" : { "units" : "kilometers" } } if ( len ( avoid ) > 0 ) : request_json [ "avoid_locations" ] = [ { "lat" : x [ 0 ] , "lon" : x [ 1 ] } for x in avoid ] self . log ( "Sending request JSON to %s: %s" % ( self . entrypoint , request_json ) ) response = requests . post ( "http://%s/route" % self . entrypoint , json = request_json , timeout = self . timeout ) data = response . content . decode ( ) self . log ( "Response: %s" % data ) if ( response . status_code == 200 ) : content = json . loads ( data ) if ( not "error" in content ) : return { "distance" : content [ "trip" ] [ "legs" ] [ 0 ] [ "summary" ] [ "length" ] * 1000 , "duration" : content [ "trip" ] [ "legs" ] [ 0 ] [ "summary" ] [ "time" ] , "response" : content } 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.
            avoid: An array of (long, lat) pairs to be avoided.

        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
from_long
from_lat
to_long
to_lat
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 .
avoid
An array of (long, lat) pairs to be avoided.
An array of ( long lat ) pairs to be avoided .
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 .