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

发布于 2024-12-02 23:21:54 字数 2850 浏览 3 评论 0原文

我在构建多边形时遇到问题。错误消息内容如下:

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

这一定是非常简单的事情,但我就是看不到它。您提供的任何提示都很有用。

我基本上是在模式窗口(带有检票口)的 iframe 内绘制地图。一切都很好,但是当我尝试显示多边形时(这些点是从数据库加载并由网络服务发送的),我收到错误消息。

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

我可以看到这些点已正确加载并带有警报,但我不断收到错误消息。

帮我!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

灯角 2024-12-09 23:21:54

我也遇到了同样的问题。
不知道这是否是最好的解决方案,可能不是,但它对我有用。

问题是 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);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文