Created
May 22, 2015 09:26
-
-
Save niiyz/76ede084d3eddb3ecb2e to your computer and use it in GitHub Desktop.
GoogleMapでWebサービスを作る説明ソース4。
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
<!DOCTYPE html> | |
<html> | |
<head lang="ja"> | |
<meta charset="UTF-8"> | |
<style> | |
#myMap { | |
width: 500px; | |
height: 500px; | |
} | |
</style> | |
</head> | |
<body> | |
<div id="myMap"></div> | |
<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js"></script> | |
<script> | |
function initialize() { | |
var latLng = new google.maps.LatLng(36.861751, 136.991468); | |
var mapOptions = { | |
zoom: 10, | |
center: latLng | |
}; | |
var div = document.getElementById("myMap"); | |
var map = new google.maps.Map(div, mapOptions); | |
// マップイベント | |
google.maps.event.addListener(map, 'click', function(event) { | |
var position = event.latLng; | |
// マーカー生成 | |
var marker = new google.maps.Marker({ | |
draggable: true, | |
position: position, | |
map: map | |
}); | |
// マーカーイベント | |
google.maps.event.addListener(marker, 'rightclick', function(event) { | |
var content = ''; | |
content += '<div>' + marker.position + '</div>'; | |
// 吹き出し生成 | |
var infoWindow = new google.maps.InfoWindow({ | |
content: content, | |
position: marker.position, | |
pixelOffset: new google.maps.Size(0, -25) | |
}); | |
infoWindow.open(map); | |
}); | |
}); | |
} | |
google.maps.event.addDomListener(window, 'load', initialize); | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment