Skip to content

Instantly share code, notes, and snippets.

@maclover7
Last active August 29, 2015 14:27
Show Gist options
  • Save maclover7/af1edb64ce8ad61f0df9 to your computer and use it in GitHub Desktop.
Save maclover7/af1edb64ce8ad61f0df9 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html>
<head>
<title>Place Autocomplete</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
</head>
<body>
<input id="city-input" class="controls" type="text"
placeholder="Enter a location">
<script>
function initMap() {
var input = /** @type {!HTMLInputElement} */(
document.getElementById('city-input'));
var autocomplete = new google.maps.places.Autocomplete(input);
var infowindow = new google.maps.InfoWindow();
autocomplete.addListener('place_changed', function() {
infowindow.close();
var place = autocomplete.getPlace();
infowindow.setContent('<div><strong>' + place.name + '</strong><br>' + address);
});
}
</script>
<script src="https://maps.googleapis.com/maps/api/js?signed_in=true&libraries=places&callback=initMap"
async defer></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment