谷歌地图接收多边形坐标

Google Maps receive polygon coordinates

本文关键字:坐标 多边形 谷歌地图      更新时间:2023-09-26

我用这个例子在google地图上画一个多边形:

http://nettique.free.fr/gmap/toolbar.html

画完一个多边形后,我想要读取我创建的多边形的坐标。所以,在文件mapToolbar.js(这是上面的例子的一部分从nettique.free.fr)在javascript函数称为stopediting(当我点击'手'按钮时运行)。

那么,读取这些坐标的解就是某种循环我读取坐标:

MapToolbar.features.shapeTab.shape_1.latLngs.b[0].b[i].ib - latitude
MapToolbar.features.shapeTab.shape_1.latLngs.b[0].b[i].jb - longitude

它工作得很好,但我的问题是,从时间的后缀ibjb改变为例如YaZa。我希望你知道这是什么意思。我必须改变我的代码;/但我不想这么做!;)

你知道如何解决这个问题吗?

MapToolbar.features.shapeTab。shape_1是google.maps.Polygon -instance.

使用getPath()检索路径,并使用forEach方法遍历路径:

  MapToolbar.features.shapeTab.shape_1.getPath().forEach(function(latLng,index){
    console.log('shape_1',index,latLng.toString());
  });