谷歌地图v3:绘制折线时构造函数参数0的值无效

3
我在构建多边形时遇到了问题。错误信息如下所示:

构造函数参数0的值无效: (49.27862248020283, -122.79301448410035),(49.277964542440955, -122.79370112960816),(49.278524490028595, -122.7950207764435)

可能是一个非常简单的错误,但我却看不出来。如果您有任何提示,请告诉我。
我基本上是在模态窗口(通过wicket)内的iframe中绘制地图。一切都正常,但当我尝试显示一个多边形(点从数据库加载并通过webservice发送)时,就会收到错误消息。
iframe代码:(仅相关部分)
 /**
 * Draws the polygon.
 */
function drawPolygon() {
    if (order >= 3) {
        deleteMarkers();

    // Construct the polygon
    // Note that we don't specify an array or arrays, but instead just
    // a simple array of LatLngs in the paths property


    polygonObject = new google.maps.Polygon({
                        paths: polygonCoords,
                        strokeColor: "#FF0000",
                        strokeOpacity: 0.8,
                        strokeWeight: 2,
                        fillColor: "#FF0000",
                        fillOpacity: 0.35
                      });

    polygonObject.setMap(map);

    isPolygonDrawed = true;

    //After we create the polygon send the points to wicket
    parent.sendPoints();

    //Change the message on the top label
    controlText.style.color = '#ADAAAA';
    controlText.innerHTML = polygonCreated;

    //With this we make sure no other markers are created after the polygon is drawed.
    //Is assigned (order - 1) because when this code is called the order has already been added 1.
    MAX_POLYGON_VERTEX = order - 1;

    //Disable the create polygon button.
    enable = false;
    createControlText.style.color = '#ADAAAA';
}
else alert(alertMessage);

现在,父级代码(模态窗口)如下:

    /**
 * Show the polygon on map.
 */
function showPolygon(zoneId) {
    var url = applicationRootUrl + 'zonePointsOnMap?zoneId=' + zoneId;
    $.getJSON(url, function(data) {
        if(data.length == 0) {
            return false;
        }
        frames['zoneMapIFrame'].order = parseInt(data.length);
        alert(data.length);
        $.each(data, function(i, item) {
            if(item != null) {
                if(item.latitude != null && item.longitude != null) {
                    var lat = parseFloat(item.latitude);
                    var lng = parseFloat(item.longitude);
                    var latlng = new google.maps.LatLng(lat, lng);
                    var pointOrder = item.order;
                    frames['zoneMapIFrame'].polygonCoords[pointOrder] = latlng;
                    alert(item.order + " point " + latlng);
                    frames['zoneMapIFrame'].bounds.extend(latlng);
                 }

            }

          });
    });
    setTimeout("frames['zoneMapIFrame'].drawPolygon()", 200); 
    setTimeout("frames['zoneMapIFrame'].fitMapZoomPolygon()", 300);
}

我发现提醒消息显示点已成功加载,但我一直收到错误消息。
帮帮我!
1个回答

2

我之前也遇到了同样的问题。虽然不确定这是否是最佳解决方案,但对我来说有效。

问题出在无法识别Latlng。因此,我重建了数组。

var lats = [];
var lat_size = steps[step].lat_lngs.length;

for (var t=0; t <lat_size; t++) {

lats.push(new google.maps.LatLng(steps[step].lat_lngs[t].lat(), steps[step].lat_lngs[t].lng()))
          }
var polylineOptions = {
map: map,
path: lats
 }

new google.maps.Polyline(polylineOptions);

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接