Closed MiniCodeMonkey closed 10 years ago
The query value is stored for looking up addresses, just not in the way represented by the service's JSON response in the docs.
In batch geocoding with pygeocodio, a LocationCollection
is made by adding each individual address response into a Location
(just slightly augmented Python list
and dict
objects, respectively). A Location
doesn't store a query, because presumably you know what it is - you just used it to geocode an address. When batch geocoding of course, that's problematic. So this module ensures that the order of the results matches the order of the addresses queried, and it stores the queries in a separate dictionary for lookup.
>>> geocoded_addresses.get('3101 Patterson Ave, Richmond, VA, 23221')
{u'input': {u'address_components': {u'city': u'Richmond', u'suffix': u'Ave', u'zip': u'23221', u'number': u'3101', u'state': u'VA', u'street': u'Patterson'}, u'formatted_address': u'3101 Patterson Ave, Richmond, VA 23221'}, u'results': [{u'address_components': {u'city': u'Richmond', u'suffix': u'Ave', u'zip': u'23221', u'number': u'3101', u'county': u'Richmond city', u'state': u'VA', u'street': u'Patterson'}, u'formatted_address': u'3101 Patterson Ave, Richmond, VA 23221', u'location': {u'lat': 37.560890255102, u'lng': -77.477400571429}, u'accuracy': 0.8}]}
Note that to perform the key based lookup you must use the get method. This preserves the list’s index based lookup.
Having batch geocoded some addresses, you can access the dictionary from the returned object via the lookups
attribute:
>>> geocoded_addresses.lookups
{'3101 Patterson Ave, Richmond, VA, 23221': 1, ...}
Where the value is the index of the address in the list. This is mostly in the pygeocodio docs although there is an extra attribute that doesn't exist mentioned there (either an old build or I failed to update the docs).
Hi Ben,
Mathias Hansen
On Sun, Mar 16, 2014 at 11:45 AM, Ben Lopatin notifications@github.com wrote:
Closed #3.
Reply to this email directly or view it on GitHub: https://github.com/bennylope/pygeocodio/issues/3
It looks like the
query
key is omitting when performing a batch geocoding request. The key is used to match up the address again after it has been geocoded.See http://geocod.io/docs/?python#toc_7 where the example response shows
query