Skip to content

Instantly share code, notes, and snippets.

@zross
Created October 21, 2014 16:18
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save zross/d301158c9729f2abbb75 to your computer and use it in GitHub Desktop.
Save zross/d301158c9729f2abbb75 to your computer and use it in GitHub Desktop.
Example of Google Places Library (get place details if you have place ID)
<!DOCTYPE html>
<html>
<head>
<title>Place details</title>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no">
<meta charset="utf-8">
<style>
html, body, #map-canvas {
height: 100%;
margin: 0px;
padding: 0px
}
</style>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=places"></script>
<script>
function initialize() {
var map = new google.maps.Map(document.getElementById('map-canvas'), {
center: new google.maps.LatLng(42.444508,-76.499491),
zoom: 15
});
var request = {
placeId: "ChIJT_x1AIOB0IkRhcd1YOHXJXk"
};
var infowindow = new google.maps.InfoWindow();
var service = new google.maps.places.PlacesService(map);
service.getDetails(request, function(place, status) {
console.log(status)
if (status == google.maps.places.PlacesServiceStatus.OK) {
console.log(place)
var marker = new google.maps.Marker({
map: map,
position: place.geometry.location
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent(place.name);
infowindow.open(map, this);
});
}
});
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="map-canvas"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment