Skip to content

Instantly share code, notes, and snippets.

@ritec
Created November 7, 2016 15:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save ritec/1960d062fc42a50b963db3fc01112f02 to your computer and use it in GitHub Desktop.
Save ritec/1960d062fc42a50b963db3fc01112f02 to your computer and use it in GitHub Desktop.
Get City and State from Zip Code with Google Geo API
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)
});
}
};
@JupiterITechno
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment