Created
November 7, 2016 15:16
-
-
Save ritec/1960d062fc42a50b963db3fc01112f02 to your computer and use it in GitHub Desktop.
Get City and State from Zip Code with Google Geo API
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
window.findAddressFromZip = function(zipcode) { | |
var city, state, zip; | |
zip = zipcode.value; | |
city = ''; | |
state = ''; | |
if (zip.length === 5) { | |
$.ajax({ | |
type: 'POST', | |
url: "http://maps.googleapis.com/maps/api/geocode/json?address=" + zip + "?key=XXXXXXXXXXXXXXXXXXXX", | |
success: (function(_this) { | |
return function(data) { | |
if (data["status"] === "OK") { | |
$('input#user_account_attributes_address_attributes_city').val(data["results"][0]["address_components"][1]["long_name"]); | |
return $('select#user_account_attributes_address_attributes_state').val(data["results"][0]["address_components"][4]["long_name"]); | |
} | |
}; | |
})(this) | |
}); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello,
I want to full code for the getting city,state,country from picode.
all files i want.
.aspx , and .aspx.cs
Please help me.