We are developing our website in django framework and with python. currently we are looking for an api/a tool to validate the physical addres the user enters. It doesn't need to be vey sophisticated. We just need to avoid spam registrations. For this step, we need to verify if country, state, city, and zipcode are belong to each other. For instance, Berkeley as a city with Zipcode 94704 is not in NY state, etc. Any thoughts?
Asked
Active
Viewed 3,468 times
2 Answers
4
You can give a try to pygeocoder. It's a Python wrapper for Google's Geocoding V3 API. It can fulfill some of your validation needs.
from pygeocoder import Geocoder
g = Geocoder()
g.geocode("1 wellington, ottawa").valid_address
>>> True
g.geocode("1 wellington, chicago").valid_address
>>> False
It can take some minor misspelling too
result = g.geocode("1600 amphiteather, mountain view")
result.valid_address
>>> True
print result
>>> 1600 Amphitheatre Pkwy, Mountain View, CA 94043, USA
g.geocode("16000000 amphitheater, mountain view").valid_address
>>> False
But Google doesn't always have the right postal/zip code. USPS has a public API for the US I believe.
disclamer: I made pygeocoder

xster
- 6,269
- 9
- 55
- 60
-
Hi! After seeing this post I went and installed pygeocoder. Seems very cool. I have a related question. Can you assist? http://stackoverflow.com/questions/24921545/how-to-assign-to-a-django-pointfield-model-attribute – Saqib Ali Jul 23 '14 at 21:42
2
You could probably use a GeoCoding service (like Google's) to verify that an address exists.

Matthew J Morrison
- 4,343
- 3
- 28
- 45
-
thanks Matthew. does it give us this ability to test if a zipcode belongs to a city or a state? i'm trying to avoid useing coordinators! – Sara Aug 23 '10 at 20:27
-
I assume, that if you pass an invalid zip code the GeoCoding service would not find the address. – Matthew J Morrison Aug 24 '10 at 02:13