LatLng class
google.maps.LatLng
class
LatLng
是地理座標中的點,也就是經緯度。
- 緯度的範圍介於正負 90 度 (含首尾)。凡是超出這個範圍,都會調整為範圍 [-90, 90] 內的值。也就是說,如果指定的值小於 -90,系統會將值設為 -90。如果值大於 90,系統會將其設為 90。
- 經度-180度到180度(含)之間的範圍。凡是超出這個範圍,都會換算為範圍內的值。舉例來說,值為 -190 會轉換為 170。190 會轉換為 -170。這反映出經度會環繞地球。
請注意,您無法修改
LatLng
的座標。如要計算其他點,請建立新點。 接受 LatLng
物件的大多數方法也會接受 LatLngLiteral
物件,因此下列項目是等效的:
map.setCenter(new google.maps.LatLng(-34, 151));
map.setCenter({lat: -34, lng: 151});
建構函式也會接受 LatLngLiteral
和 LatLng
物件。如果將 LatLng
例項傳遞至建構函式,系統會建立副本。
建構函式的可能呼叫如下:
new google.maps.LatLng(-34, 151);
new google.maps.LatLng(-34, 151, true);
new google.maps.LatLng({lat: -34, lng: 151});
new google.maps.LatLng({lat: -34, lng: 151}, true);
new google.maps.LatLng(new google.maps.LatLng(-34, 151));
new google.maps.LatLng(new google.maps.LatLng(-34, 151), true);
撥打 const {LatLng} = await google.maps.importLibrary("core")
即可存取。
請參閱「Maps JavaScript API 中的程式庫」。
建構函式 | |
---|---|
LatLng |
LatLng(latOrLatLngOrLatLngLiteral[, lngOrNoClampNoWrap, noClampNoWrap]) 參數:
建立代表地理位置點的 LatLng 物件。緯度以度為單位指定,範圍為 [-90, 90]。經度以度為單位,範圍為 [-180, 180)。將 noClampNoWrap 設為 true ,即可啟用這個範圍以外的值。請注意經緯度的順序。 |
方法 | |
---|---|
equals |
equals(other) 參數:
傳回值:
boolean Comparison 函式。 |
lat |
lat() 參數:無
傳回值:
number 傳回緯度 (以度為單位)。 |
lng |
lng() 參數:無
傳回值:
number 傳回經度 (以度為單位)。 |
toJSON |
toJSON() 參數:無
傳回值:
LatLngLiteral 轉換為 JSON 表示法。這項函式適用於 JSON.stringify 。 |
|