LatLngBounds.getNorthEast()
LatLng.getNorthEast()はLatLngBoundsクラスのメソッドです。境界の北東(右上)の位置座標を取得できます。
構文
getNorthEast()
パラメータ
パラメータはありません。
返り値
LatLng
境界の北東(右上)の位置座標。
デモ
メソッドを実行すると、境界の北東(右上)の位置座標を取得します。分かりやすいように境界には色を付けてあります。
var latLngBounds = new google.maps.LatLngBounds(
new google.maps.LatLng( 35.2199, 136.9851 ) ,
new google.maps.LatLng( 37.7892, 140.4898 )
) ;
// メソッドを実行
latLngBounds.getNorthEast() ;
サンプルコード
<!DOCTYPE html>
<html>
<head>
<style>
#map-canvas {
width: 600px ;
height: 600px ;
}
</style>
</head>
<body>
<div id="map-canvas"></div>
<p><button id="method">メソッドを実行</button><button id="reset">リセット</button></p>
<p><textarea id="response"></textarea></p>
<script src="//maps.googleapis.com/maps/api/js?key={APIキー}"></script>
<script>
function initialize() {
var mapDiv = document.getElementById( "map-canvas" ) ;
var responseTextarea = document.getElementById( "response" ) ;
responseTextarea.value = "" ;
// Map
var map = new google.maps.Map( mapDiv, {
center: new google.maps.LatLng( 35, 139 ) ,
zoom: 15 ,
} ) ;
// LatLngBounds
var latLngBounds = new google.maps.LatLngBounds(
new google.maps.LatLng( 33.35929104,134.93065664 ) ,
new google.maps.LatLng( 36.95102297,141.68730977 )
) ;
// LatLngBoundsを可視化
new google.maps.Rectangle( { map: map, bounds: latLngBounds, } ) ;
// fit bounds
map.fitBounds( latLngBounds ) ;
// Method
document.getElementById( "method" ).onclick = function () {
var response = latLngBounds.getNorthEast() ;
new google.maps.Marker( { map: map, position: response, } ) ;
try{ response = typeof response == "object" ? JSON.stringify( response ) : response ; }catch(e){}
responseTextarea.value = response ;
console.log( response ) ;
}
}
// Reset
document.getElementById( "reset" ).onclick = initialize ;
initialize() ;
</script>
</body>
</html>