Geometry Library

encoding class

google.maps.geometry.encoding class

折線編碼及解碼的公用程式。

撥打 const {encoding} = await google.maps.importLibrary("geometry") 即可存取。
請參閱「Maps JavaScript API 中的程式庫」。

decodePath
decodePath(encodedPath)
參數: 
  • encodedPathstring
傳回值:  Array<LatLng>
將編碼路徑字串解碼為 LatLngs 序數。
encodePath
encodePath(path)
傳回值:  string
將 LatLngs 的序數編碼為編碼路徑字串。

spherical class

google.maps.geometry.spherical class

計算測地線角度、距離及面積的公用程式函式。預設半徑為 6378137 公尺的地球半徑。

撥打 const {spherical} = await google.maps.importLibrary("geometry") 即可存取。
請參閱「Maps JavaScript API 中的程式庫」。

computeArea
computeArea(path[, radiusOfSphere])
傳回值:  number
傳回封閉路徑的未簽署面積,範圍為 [0, 2×pi×radius²]。計算出的面積與半徑使用相同單位。radiusOfSphere 預設為地球半徑 (以公尺為單位),此時面積單位為平方公尺。如要傳遞 Circleradius 必須設為非負值。此外,圓圈不得覆蓋超過 100% 的球體。傳遞 LatLngBounds 時,南方的 LatLng 不得比北方的 LatLng 更北。
computeDistanceBetween
computeDistanceBetween(from, to[, radius])
參數: 
傳回值:  number
傳回兩個 LatLng 之間的距離 (單位為公尺)。您可以視需要指定自訂半徑。半徑預設為地球半徑。
computeHeading
computeHeading(from, to)
參數: 
傳回值:  number
傳回從一個 LatLng 到另一個 LatLng 的方位。方向以度為單位,從正北順時針移動,範圍為 [-180,180)。
computeLength
computeLength(path[, radius])
參數: 
傳回值:  number
傳回指定路徑的長度。
computeOffset
computeOffset(from, distance, heading[, radius])
參數: 
傳回值:  LatLng
傳回從原點沿指定方位 (以順時針方向從正北算起,以度為單位) 移動一段距離後所得的 LatLng。
computeOffsetOrigin
computeOffsetOrigin(to, distance, heading[, radius])
參數: 
傳回值:  LatLng|null
如果提供 LatLng 目的地、行駛距離 (以公尺為單位) 和原始航向,系統會傳回起點位置。方向以度為單位,從正北順時針移動。如果沒有可用的解決方案,這個函式會傳回 null
computeSignedArea
computeSignedArea(loop[, radius])
參數: 
傳回值:  number
傳回封閉路徑的帶正負號面積,逆時針方向為正值,範圍為 [-2×pi×radius²,2×pi×radius²]。計算出的面積與半徑使用相同單位。半徑預設為地球半徑 (以公尺為單位),此時面積單位為平方公尺。

面積是使用平行傳輸方法計算;單位球體上封閉路徑周圍的平行傳輸會扭曲一個角度,該角度等於路徑所圍成的面積。與使用 Girard、l'Huilier 或 Eriksson 對每個三角形進行三角測量相比,這種方法更簡單、準確且穩健。特別是,由於不會進行三角剖分,因此除了多邊形的「邊緣」 (非對角線) 跨越 180 度時,不會發生不穩定情況。
interpolate
interpolate(from, to, fraction)
參數: 
傳回值:  LatLng
傳回 LatLng,該 LatLng 位於起點 LatLng 和目的地 LatLng 之間,且與起點 LatLng 的距離占兩者距離的指定比例。

poly class

google.maps.geometry.poly class

用於計算多邊形和折線的公用函式。

撥打 const {poly} = await google.maps.importLibrary("geometry") 即可存取。
請參閱「Maps JavaScript API 中的程式庫」。

containsLocation
containsLocation(point, polygon)
參數: 
傳回值:  boolean
計算指定點是否位於指定多邊形內。
isLocationOnEdge
isLocationOnEdge(point, poly[, tolerance])
參數: 
傳回值:  boolean
計算指定點是否位於折線/多邊形邊緣上或附近,並在指定公差內。如果所提供點的經緯度與邊緣上最近點的經緯度之間的差異小於容差,則會傳回 true。預設公差為 10-9 度。