Skip to content

Instantly share code, notes, and snippets.

@SpencerCooley
Created September 13, 2012 17:37
Show Gist options
  • Save SpencerCooley/3716085 to your computer and use it in GitHub Desktop.
Save SpencerCooley/3716085 to your computer and use it in GitHub Desktop.
var geocoder = new google.maps.Geocoder();
$("#address").autocomplete({
//This bit uses the geocoder to fetch address values
source: function(request, response) {
geocoder.geocode( {'address': request.term }, function(results, status) {
response($.map(results, function(item) {
return {
label: item.formatted_address,
value: item.formatted_address,
latitude: item.geometry.location.lat(),
longitude: item.geometry.location.lng()
}
}));
})
},
//This bit is executed upon selection of an address
select: function(event, ui) {
$("#lat").val(ui.item.latitude);
$("#lng").val(ui.item.longitude);
}
});
//the css
.ui-autocomplete {
background-color: white;
width: 300px;
border: 1px solid #cfcfcf;
list-style-type: none;
padding-left: 0px;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment