来自Google Maps多边形的LatLng getPath() [英] LatLng from Google Maps Polygon getPath()
问题描述
根据 Google Maps JavaScript API v3文档, google.maps.Polygon
类的 getPath()
函数返回一个 MVCArray
。在一个简单的例子中,一个Polygon的路径可以是 LatLngs
的单个数组,它被转换为 MVCArray
类型传递给google.maps.Polygon类的 setPath()
函数。上面的例子是我的处理目前。我传入一个 LatLngs
数组,当我调用<$ c时返回(我认为是) MVCObject
$ c> getPath()在我的Polygon对象上。我的问题是:如何将这个 MVCObject
转换回构成Polygon形状的 LatLngs
的单个数组?是否有一些内置Google Maps API v3的方式,我错过了?我觉得必须有一些明显的内置转换函数或API中的某些内容,这些都是我不知道的。
任何帮助都将不胜感激。
当您调用 Polygon.getPath()
api-doc ,返回的是 MVCArray code> api-doc
LatLng
表示 Polygon
的第一个路径的实例。您可以通过两种方式直接进入 MVCAarray
的成员:
- 打电话
MVCAarray.getArray
,它将返回包含LatLng $ c的基础JavaScript
Array
$ c $> - 使用
MVCArray.getAt(index)
,它会返回MVCArray
(在这种情况下,aLatLng
)。这为您提供了一种为循环设置JavaScript循环来遍历数组成员的方法。
您也可以通过使用 forEach(callback:function(*,number))间接处理
函数。在这种情况下,您必须传递一个回调函数,它接受两个参数: MVCArray
的成员
-
MVCArray的实际成员元素
。 - 该元素所在的数组索引。
Based on the Google Maps JavaScript API v3 documentation, google.maps.Polygon
class's getPath()
function returns an MVCArray
. In a straightforward case, a Polygon's path can be a single array of LatLngs
that are converted to the MVCArray
type upon being passed into the google.maps.Polygon class's setPath()
function.
The above case is what I'm dealing with currently. I pass in an array of LatLngs
, and return (what I assume is) an MVCObject
when I call getPath()
on my Polygon object. My question is: How do I convert this MVCObject
back into a single array of LatLngs
that form the Polygon's shape? Is there some built in Google Maps API v3 way that I'm missing? I feel like there has to be some sort of obvious built in conversion function or something in the API that's eluding me.
Any help would be appreciated.
When you call Polygon.getPath()
api-doc, the return is an MVCArray
api-doc of LatLng
instances that represent the first path of the Polygon
. You can directly get to the members of the MVCAarray
in two ways:
- Call
MVCAarray.getArray
, which will return the underlying JavaScriptArray
that containsLatLng
members. - Use
MVCArray.getAt( index )
, which will return whatever is at that index in theMVCArray
(aLatLng
in this case). This provides you a way to setup a JavaScriptfor
loop to iterate over the members of the array.
You can also indirectly work with the members of the MVCArray
by using the forEach(callback:function(*, number))
function. In this case, you must pass a callback function that accepts two parameters:
- The actual member element of the
MVCArray
. - The array index where that element is located.
这篇关于来自Google Maps多边形的LatLng getPath()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!