Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retrieving location accuracy with geopy

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.

like image 305
geoAndrew Avatar asked Oct 22 '25 12:10

geoAndrew


1 Answers

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!

like image 92
geoAndrew Avatar answered Oct 25 '25 02:10

geoAndrew