来自Google Maps多边形的LatLng getPath() [英] LatLng from Google Maps Polygon getPath()

查看:72
本文介绍了来自Google Maps多边形的LatLng 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 的成员:


  1. 打电话 MVCAarray.getArray ,它将返回包含 LatLng Array $ c $>

  2. 使用 MVCArray.getAt(index),它会返回 MVCArray (在这种情况下,a LatLng )。这为您提供了一种为循环设置JavaScript 循环来遍历数组成员的方法。

您也可以通过使用 forEach(callback:function(*,number))间接处理 MVCArray 的成员函数。在这种情况下,您必须传递一个回调函数,它接受两个参数:


  1. MVCArray的实际成员元素

  2. 该元素所在的数组索引。


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 MVCArrayapi-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:

  1. Call MVCAarray.getArray, which will return the underlying JavaScript Array that contains LatLng members.
  2. Use MVCArray.getAt( index ), which will return whatever is at that index in the MVCArray (a LatLng in this case). This provides you a way to setup a JavaScript for 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:

  1. The actual member element of the MVCArray.
  2. The array index where that element is located.

这篇关于来自Google Maps多边形的LatLng getPath()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆