Skip to content

Instantly share code, notes, and snippets.

@cowgill
Created December 17, 2016 07:03
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 cowgill/86554dc571e54771e301b8f6e6d3f893 to your computer and use it in GitHub Desktop.
Save cowgill/86554dc571e54771e301b8f6e6d3f893 to your computer and use it in GitHub Desktop.
Google maps address autocomplete example
<html>
<head>
<script type='text/javascript' src='//maps.googleapis.com/maps/api/js?libraries=places&#038;region=us&#038;language=en&#038;unit=mi&#038;key=AIzaSyCg7Bzy277zhIIYinvQN0Q9sPr8s&#038;callback'></script>
<script>
jQuery( function( $ ) {
function testMapAutoCompleteInit() {
var input = document.getElementById( 'address' );
// Exit if no dropdown div is found.
if ( null === input ) {
return;
}
var autoComplete = new google.maps.places.Autocomplete(
input, {
types: [ 'geocode' ]
}
);
}
// Trigger the listener.
google.maps.event.addDomListener( window, 'load', testMapAutoCompleteInit );
} );
</script>
</head>
<body>
<input class="required" id="address" name="address" value="" type="text">
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment