Google Maps Api:polygoneCoords = [javascriptvariable];

威猛(Vermeer)

我如何阅读以下内容:

var polygoneCoords = [javascriptvariable];

代替

var polygoneCoords = [new google.maps.LatLng(49.91727104462425, 10.872366428375244) ,new google.maps.LatLng(49.91740920888044, 10.872366428375244)];

当然,我已经定义了“ javascriptvariable”,但是我只能得到:

未捕获的InvalidValueError:索引为0:不是LatLng或LatLngLiteral:不是对象”

ffflabs

google.maps.Polygon对象可以包含一个或多个路径。每个路径都是由坐标组成的数组(或MVCArray)。每个坐标依次是google.maps.LatLng对象或LatLngLiteral。

这意味着您可以将其声明为

var polygoneCoords = [new google.maps.LatLng(49.91727104462425, 10.872366428375244),new google.maps.LatLng(49.91740920888044, 10.872366428375244)];

或作为

var polygoneCoords = [{lat:49.91727104462425,lng: 10.872366428375244},{lat:49.91740920888044, lng: 10.872366428375244}];

任何其他路径声明都会产生您现在看到的错误。

我希望您的多边形得到两个以上的顶点,否则它将严重不足。

因此,特别是对于您的问题,您可以自由使用第二种语法并执行以下操作:

var javascriptvariable = [{lat:49.91727104462425,lng: 10.872366428375244},{lat:49.91740920888044, lng: 10.872366428375244}];

var myPolygon=new google.maps.Polygon({map:map});

myPolygon.setPath(javascriptvariable);

但是,我看到您将javascriptvariable括在方括号中。如果是故意的,那么您将尝试将数组数组声明为Path(您不能这样做),但是由于Polygon可以有多个路径,因此您可以

myPolygon.setPaths([javascriptvariable]);

这意味着与以前的表示法大致相同。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章