Last active
January 3, 2016 08:18
-
-
Save myamamic/8434801 to your computer and use it in GitHub Desktop.
[gtuggirls] GTUG Girls #15 サンプル5
This file contains hidden or 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
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>Place searches</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&sensor=false&libraries=places"></script> | |
<script> | |
var map; | |
var infowindow; | |
function initialize() { | |
var ginza = new google.maps.LatLng(35.6708529, 139.7605315); | |
map = new google.maps.Map(document.getElementById('map-canvas'), { | |
center: ginza, | |
zoom: 16 | |
}); | |
var request = { | |
location: ginza, | |
radius: 500, | |
types: ['store'] | |
//types: ['hair_care'] | |
}; | |
infowindow = new google.maps.InfoWindow(); | |
var service = new google.maps.places.PlacesService(map); | |
service.nearbySearch(request, callback); | |
} | |
function callback(results, status) { | |
if (status == google.maps.places.PlacesServiceStatus.OK) { | |
for (var i = 0; i < results.length; i++) { | |
createMarker(results[i]); | |
} | |
} | |
} | |
function createMarker(place) { | |
var placeLoc = place.geometry.location; | |
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