Skip to content

Instantly share code, notes, and snippets.

@nakaji
Created December 18, 2014 19:45
Show Gist options
  • Save nakaji/b1d10df9667f501efe46 to your computer and use it in GitHub Desktop.
Save nakaji/b1d10df9667f501efe46 to your computer and use it in GitHub Desktop.
GoogleMapで表示されている地図の範囲を表示する ref: http://qiita.com/nakaji/items/68e86712d88d22365233
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>表示されている地図の範囲を表示する</title>
<script src="scripts/jquery-1.10.2.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?v=3.exp"></script>
<script>
$(function () {
google.maps.event.addDomListener(window, 'load', initialize);
function initialize() {
var myLatlng = new google.maps.LatLng(33.839193, 132.765563);
var mapOptions = {
zoom: 15,
center: myLatlng
}
var map = new google.maps.Map(document.getElementById('map-canvas'), mapOptions);
google.maps.event.addListener(map, 'bounds_changed', function () {
$("#addressList").val(
"北東:" + map.getBounds().getNorthEast().lat() + "," + map.getBounds().getNorthEast().lng() + "\r\n" +
"南西:" + map.getBounds().getSouthWest().lat() + "," + map.getBounds().getSouthWest().lng()
);
});
}
});
</script>
</head>
<body>
<h1>表示されている地図の範囲を表示する</h1>
<textarea style="width: 100%; height: 50px;" id="addressList"></textarea>
<div id="map-canvas" style="height: 250px;width: 500px;margin: 20px;padding: 20px;"></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment