user695663
user695663

Reputation: 12356

Updating state and zipcode based on the IP address

I have a field where user inputs Zip code. Based on the value entered I want to populate city and state. How i can do this in jQuery?

Upvotes: 1

Views: 1226

Answers (1)

Gal
Gal

Reputation: 5907

You can use Google's Map / Geocoding API, here is a quick demo:

<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
    alert(google.loader.ClientLocation.address.city);
</script>

http://jsfiddle.net/zwPvs/1/

edit: Since the user is communicating directly with Google's servers, you don't even have to pass in an IP address, they figure it out. They may even use some additional points of data beyond IP address, but not sure.

Upvotes: 2

Related Questions