「bounds_changed」は表示領域が変更された時に発生するイベントです。
「center_changed」の場合は中心を変えないでズームした場合はイベントは発生しませんが、
こちらの場合は表示領域がトリガーになっているのでイベントは発生します。
以下サンプルです。
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8" />
<title> google maps api v3</title>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false"> </script>
<script type="text/javascript">
google.maps.event.addDomListener(window, "load", function () {
var map = document.getElementById("map_canvas");
var latlng = new google.maps.LatLng(35.658580, 139.745433);
var mapOptions = {
zoom: 18,
center: latlng
};
var gmap = new google.maps.Map(map, mapOptions);
google.maps.event.addListener(gmap, "bounds_changed", function () {
var note = document.getElementById("note");
note.innerText = "bounds = " + gmap.getBounds();
});
});
</script>
</head>
<body>
<div id="map_canvas" style="width: 400px; height: 400px"> </div>
<p id="note" style="padding: 10px; background-color:#f50; color: #fff;">
</p>
</body>
</html>
0 件のコメント:
コメントを投稿