SYNCERのロゴ
アイキャッチ画像

LatLng.lng()

LatLng.lng()はLatLngクラスのメソッドです。インスタンスが含んでいる位置座標の情報のうち、経度を返します。

構文

lng()

パラメータ

パラメータはありません。

返り値

number

経度を数値で返す。

デモ

メソッドを実行すると、位置座標のインスタンスの、経度を取得します。LatLngクラスの内容を変更して、結果を確認してみて下さい。位置座標には分かりやすいようにマーカーを設置してます。

var latLng = new google.maps.LatLng( 35.708194, 139.808565 ) ;

// メソッドを実行
latLng.lng() ;

サンプルコード

<!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 ,
	} ) ;

	// LatLng
	var latLng = new google.maps.LatLng( 35, 139 ) ;

	// LatLngを可視化
	new google.maps.Marker( { map: map, position: latLng, } ) ;

	// Method
	document.getElementById( "method" ).onclick = function () {
		var response = latLng.lng() ;
		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>

デモページを開く

  • Twitterでシェア
  • Facebookでシェア
  • Google+でシェア
  • はてなブックマークでシェア
  • pocketに保存
  • LINEでシェア
更新履歴
2015年9月1日 (火)
コンテンツを公開しました。