Tuesday, June 18, 2013

python. geocoding whith geopy

What if you have a bunch of mail addresses and need to get approximate coordinate positions? That's what geocoding is all about, and with geopy is as easy as it gets.

from geopy import geocoders
g = geocoders.GoogleV3()
place, (lat,lng) = g.geocode("AV. DIVISION DEL NORTE NO. 911-A COLONIA DEL VALLE BENITO JUAREZ")
print "%s: %.5f, %.5f" % (place, lat, lng)

And then, as if it were some sort of magic:

Avenida DivisiĆ³n del Norte 911, General Anaya, Benito Juarez, Mexico City, Federal District, Mexico: 19.35731, -99.15289


geopy includes geocoder classes for MediaWiki (with the GIS extension), Semantic MediaWiki, the Google v2 geocoder, the Yahoo! geocoder,geocoder.usBing Maps API, and GeoNames. The geocoder classes are located in geopy.geocoders.


No comments:

Post a Comment