Data types

The client returns values represented by lightly-extended Python dictionaries and lists. They have been extended to provide easier access to frequently requested or primary data elements, and to make accessing data simple.

By adding only a few methods and data lookup elements the source data is largely left as-is for developers to use as they see fit.

Address

An Address object is just a dictionary object that provides two access methods for returning the accuracy value of the geocoded address as an attribute and the coordinates of the address as an attribute.

Address.__init__(results_list, order='lat')

results_list is the raw data

order allows you to change the default order of the coordinate points. Setting order to ‘lng’ or any value other than ‘lat’ will return the points in (longitude, latitude) order.

Address.coords()

A property method that returns the coordinates of the address or None if they are not available (in the case of a parsed address).

Address.accuracy()

A property method that returns the accuracy rating of the geocoded address.

When parsing an address, the result is returned as an Address for consistency, but the result’s usefullness will be limited to the dictionary structure.

Location

A Location object is a dictionary object that provides the same access methods as an Address object. Because a geocoded Location may have more than one address returned, the methods refer to the coordinates and accuracy respectively of the most most accurate geocoded address.

Location.__init__(results_dict, order='lat')

results_dict is the raw data

order allows you to change the default order of the coordinate points. Setting order to ‘lng’ or any value other than ‘lat’ will return the points in (longitude, latitude) order.

Location.coords()

A property method that returns the coordinates of the best matched address or None if they are not available.

Location.accuracy()

A property method that returns the accuracy rating of the best matched address.

LocationCollection

A LocationCollection object is a list of Location objects. It maintains an internal dictionary of each geocoding or reverse geocoding query with reference to the list index of the result. This allows the order of the list to be preserved but for simple lookup of the values without needing to iterate over the entire list.

Note

This demands an OrderedDict! Unfortunately OrderedDict was only introduced in Python 2.7, and Python 2.6 is a targeted supported version of Python for this project. So, boo.

LocationCollection.get(key)

A method that returns a Location object from the list of locations by checking against the query input.

The key can be the queried address as a string (geocoding) or the queried point (reverse geocoding). The point can be provided as a tuple of floats:

(33.12, -78.123)

a tuple of float-coerceable values (e.g. a float as a string):

("33.12", "-78.123")

or a string representing the query:

"33.12, -78.123"

This method is provided instead of overriding the __getitem__ method as the latter allows index based access to the list.

LocationCollection.coords()

A property method that returns a list of all of the coordinates