谷歌地图v3:绘制折线时,构造函数参数0的值无效 [英] google maps v3: Invalid value for constructor parameter 0 while drawing polylines

查看:176
本文介绍了谷歌地图v3:绘制折线时,构造函数参数0的值无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

构建多边形时遇到问题。错误消息表明如下所示:


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

这一定很荒唐,但我看不到它。你有任何提示都很有用。

我基本上在一个模式窗口(使用wicket)在iframe中绘制地图。一切都很好,但是当我试图显示一个多边形时(点从数据库加载并由webservice发送),我收到了错误消息。



iframe代码: (只有相关的)

  / ** 
*绘制多边形。
* /
函数drawPolygon(){
if(order> = 3){
deleteMarkers();

//构造多边形
//请注意,我们不指定数组或数组,而只是
//路径属性$中的LatLng的简单数组b

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

polygonObject.setMap(map);

isPolygonDrawed = true;

//创建多边形后,将点发送给wicket
parent.sendPoints();

//更改顶部标签上的消息
controlText.style.color ='#ADAAAA';
controlText.innerHTML = polygonCreated;

//通过这个,我们确保在绘制多边形后不会创建其他标记。
//被赋值(order-1),因为当这个代码被调用时,订单已经被添加1.
MAX_POLYGON_VERTEX = order - 1;

//禁用创建多边形按钮。
enable = false;
createControlText.style.color ='#ADAAAA';
}
else alert(alertMessage);

}

父(模式窗口)

  / ** 
*在地图上显示多边形。
* /
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。经度);
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);
}

我可以看到点数已经加载好了,但是我一直在错误信息。



帮助我!

解决方案

一样的问题。
不知道它是否是最好的解决方案,可能不是,但它对我有用。



问题在于Latlng没有被识别。所以我重新创建了数组。

  var lats = []; 
var lat_size = steps [step] .lat_lngs.length; (var t = 0; 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);


I have a problem when constructing a polygon. The error message says something like:

Invalid value for constructor parameter 0: (49.27862248020283, -122.79301448410035),(49.277964542440955, -122.79370112960816),(49.278524490028595, -122.7950207764435)

It must be something ridiculously simple, but I just can't see it. Any tips you have are useful.

I'm basically painting a map inside an iframe on a modal window (with wicket). Everything is ok, but when I'm trying show a polygon (the points are loaded from a database and sent by webservice) I get the error message.

iframe code: (only the relevant)

 /**
 * 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);

}

Now the code on the parent (the modal window)

    /**
 * 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);
}

I can see that the points are loaded ok with alerts, but I keep getting the error message.

Help me!

解决方案

I was having the same problem. Don't know if its the best solution, probably not, but it worked for me.

The problem was that the Latlng weren't being recognized. So I recreated the array.

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);

这篇关于谷歌地图v3:绘制折线时,构造函数参数0的值无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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