Skip to content

Instantly share code, notes, and snippets.

@spheiros
Created November 12, 2014 16:04
Show Gist options
  • Save spheiros/c30290e4c50ec1d94a5d to your computer and use it in GitHub Desktop.
Save spheiros/c30290e4c50ec1d94a5d to your computer and use it in GitHub Desktop.
Find city and region from zipcode using Google Geotagging API
$.ajax({
url: 'https://maps.googleapis.com/maps/api/geocode/json',
data: {
address: loc,
language: $('.container').data('lang')
},
success: function(results, status) {
results.results[0].address_components.forEach(function(i) {
if ($.inArray('administrative_area_level_2', i.types) !== -1) {
return $('input[name=region]').val(i.long_name);
} else if ($.inArray('locality', i.types) !== -1) {
return $('input[name=city]').val(i.long_name);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment