Created
December 17, 2016 07:03
-
-
Save cowgill/86554dc571e54771e301b8f6e6d3f893 to your computer and use it in GitHub Desktop.
Google maps address autocomplete example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<html> | |
<head> | |
<script type='text/javascript' src='//maps.googleapis.com/maps/api/js?libraries=places&region=us&language=en&unit=mi&key=AIzaSyCg7Bzy277zhIIYinvQN0Q9sPr8s&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