Beispiel #1
0
    def test_location_coords(self):
        """Ensure Location.coords property returns a suitable tuple"""
        x = Location(self.single_response)
        self.assertEqual(x.coords, (37.554895702703, -77.457561054054))

        # Do the same with the order changed
        x = Location(self.single_response, order="lng")
        self.assertEqual(x.coords, (-77.457561054054, 37.554895702703))
Beispiel #2
0
 def reverse_point(self, latitude, longitude, **kwargs):
     """
     Method for identifying an address from a geographic point
     """
     fields = ",".join(kwargs.pop('fields', []))
     point_param = "{0},{1}".format(latitude, longitude)
     response = self._req(verb="reverse",
                          params={
                              'q': point_param,
                              'fields': fields
                          })
     if response.status_code != 200:
         return error_response(response)
     return Location(response.json())
Beispiel #3
0
 def test_location_results_missing(self):
     """Ensure empty results are processed as a missing address"""
     bad_results = Location(self.missing_results)
     self.assertEqual(bad_results.coords, None)
Beispiel #4
0
    def geocode_address(self, address, **kwargs):
        """
        Returns a Location dictionary with the components of the queried
        address and the geocoded location.

        >>> client = GeocodioClient('some_api_key')
        >>> client.geocode("1600 Pennsylvania Ave, Washington DC")
        {
        "input": {
            "address_components": {
                "number": "1600",
                "street": "Pennsylvania",
                "suffix": "Ave",
                "city": "Washington",
                "state": "DC"
            },
            "formatted_address": "1600 Pennsylvania Ave, Washington DC"
        },
        "results": [
            {
                "address_components": {
                    "number": "1600",
                    "street": "Pennsylvania",
                    "suffix": "Ave",
                    "city": "Washington",
                    "state": "DC",
                    "zip": "20500"
                },
                "formatted_address": "1600 Pennsylvania Ave, Washington DC, 20500",
                "location": {
                    "lat": 38.897700000000,
                    "lng": -77.03650000000,
                },
                "accuracy": 1
            },
            {
                "address_components": {
                    "number": "1600",
                    "street": "Pennsylvania",
                    "suffix": "Ave",
                    "city": "Washington",
                    "state": "DC",
                    "zip": "20500"
                },
                "formatted_address": "1600 Pennsylvania Ave, Washington DC, 20500",
                "location": {
                    "lat": 38.897700000000,
                    "lng": -77.03650000000,
                },
                "accuracy": 0.8
                }
            ]
        }
        """
        fields = ",".join(kwargs.pop("fields", []))
        response = self._req(verb="geocode",
                             params={
                                 "q": address,
                                 "fields": fields
                             })
        if response.status_code != 200:
            return error_response(response)

        return Location(response.json())