3

I have several thousand addresses to geocode at a time and am using geopy in a Django application to loop through a table which contains the addresses. I need fairly precise location coordinates and so "approximate" means an unsuccessful geocode for me.

According the the google API, this information is returned as "location_type." Bing uses confidence. I have searched the docs for both geopy and geocoder (along with Stack, etc) and can't find how to retrieve this information.

How do I return location accuracy using geopy?

Thank you for any assistance.

geoAndrew
  • 347
  • 1
  • 12

1 Answers1

3

OK, some I'm a bit of an idiot! Thought I'd checked the raw property, but obviously not closely enough!

To retrieve accuracy information from Geopy, query the .raw property.

if coder == 'google':
  location = google_locator.geocode(geocode_address)
  accuracy = location.raw['geometry']['location_type']

elif coder == 'bing':
  location = bing_locator.geocode(geocode_address)
  accuracy = location.raw['confidence']

You need to reference the APIs listed above for any assistance the correct addressing. Used pprint(location.raw) to display what was available.

Hopefully this is useful to someone else!

geoAndrew
  • 347
  • 1
  • 12