Created
January 16, 2014 08:37
-
-
Save myamamic/8451626 to your computer and use it in GitHub Desktop.
[gtuggirls] GTUG Girls #15 サンプル6拡張版
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 { | |
height: 100%; | |
margin: 0px; | |
padding: 0px | |
} | |
#map-canvas { | |
height: 100%; | |
width: 80%; | |
float: left; | |
} | |
#panel { | |
height: 100%; | |
width: 20%; | |
float: right; | |
} | |
</style> | |
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp&sensor=false&libraries=places"></script> | |
<script> | |
var ginza = new google.maps.LatLng(35.6708529, 139.7605315); | |
var directionsDisplay; | |
var directionsService = new google.maps.DirectionsService(); | |
var map; | |
var infowindow; | |
function initialize() { | |
directionsDisplay = new google.maps.DirectionsRenderer(); | |
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); | |
directionsDisplay.setMap(map); | |
// 道順案内を設定する | |
directionsDisplay.setPanel(document.getElementById("panel")); | |
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); | |
// ルート検索を実行する | |
calcRoute(ginza, marker.getPosition()) | |
}); | |
} | |
function calcRoute(src, dst) { | |
var request = { | |
origin:src, | |
destination:dst, | |
travelMode: google.maps.TravelMode.WALKING | |
}; | |
directionsService.route(request, function(response, status) { | |
if (status == google.maps.DirectionsStatus.OK) { | |
directionsDisplay.setDirections(response); | |
} | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> | |
</head> | |
<body> | |
<div id="map-canvas"></div> | |
<div id="panel"></div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment