Skip to content

Instantly share code, notes, and snippets.

@zukasmichael
Forked from badsyntax/gist:4330899
Created July 24, 2013 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zukasmichael/6073791 to your computer and use it in GitHub Desktop.
Save zukasmichael/6073791 to your computer and use it in GitHub Desktop.
/**
* Threw together by Richard Willis - badsyntax.co
*/
var service = new google.maps.places.AutocompleteService();
var geocoder = new google.maps.Geocoder();
$(field).typeahead({
source: function(query, process) {
service.getPlacePredictions({ input: query }, function(predictions, status) {
if (status == google.maps.places.PlacesServiceStatus.OK) {
process($.map(predictions, function(prediction) {
return prediction.description;
}));
}
});
},
updater: function (item) {
geocoder.geocode({ address: item }, function(results, status) {
if (status != google.maps.GeocoderStatus.OK) {
alert('Cannot find address');
return;
}
map.setCenter(results[0].geometry.location);
map.setZoom(12);
});
return item;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment