【问题标题】:Google Maps API MVCArray isn't being accepted by Polyline()Polyline() 不接受 Google Maps API MVCArray
【发布时间】:2011-05-27 19:26:23
【问题描述】:

我有一个简单的代码绘制标记,然后用折线将它们连接在一起,但我尝试与折线一起使用的 MVCArray 不起作用(并且“不起作用”我的意思是折线不是正在绘制)。这是我的代码:

$(document).ready(function(){
    var latlng = new google.maps.LatLng(36.686041,-80.661621);
    var map = new google.maps.Map(document.getElementById("network_map"),{
        zoom: 6,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    });

    $("input[name='submit']").click(function() {
        var geocoder = new google.maps.Geocoder();
        var locations = new google.maps.MVCArray();
        var i = 0;
        $("input[name='address[]']").each(function() {
            geocoder.geocode({"address" : this.value }, function(results) {
                var addrLl = results[0].geometry.location;
                locations.insertAt(locations.length, addrLl);
                var marker = new google.maps.Marker({
                    map: map,
                    position: addrLl
                });
            });
        });
        console.log(locations);
        var connectPath = new google.maps.Polyline({
            path: locations,
            strokeColor: "#FF0000",
            strokeOpacity: 1.0,
            strokeWeight: 100,
            map: map
        });
        return false;
    });
});

// console.log(locations); result from firebug
W { b=[0], gm_accessors_={...}, length=0}

【问题讨论】:

  • 你确定这不是错字吗:strokeOpacity: 1.,
  • 我确定。我尝试删除它以防万一但同样的问题。我可以通过使用此站点上的坐标示例code.google.com/apis/maps/documentation/javascript/… 使折线工作
  • 在该示例中,strokeOpacity 是“1.0”,而不是“1”。就像你上面的代码一样。不管它可能无关紧要,它只是立即突出。
  • 没关系,但我已修复它,但仍然遇到同样的问题。
  • 我解决了我的问题,但我没有足够高的声誉来发布解决方案 8 小时...基本上,我所要做的就是确保地理编码器已完成对最后一个地址的地理编码在我将 MVCArray 发送到折线之前。我会尽快发布修复程序。

标签: javascript jquery google-maps google-maps-api-3


【解决方案1】:

我能够通过设置 100 毫秒超时来解决我的问题,以防止 MVCArray 在地理编码器完成地理编码之前被发送到折线。

【讨论】:

    猜你喜欢
    • 2013-02-06
    • 1970-01-01
    • 1970-01-01
    • 2016-10-08
    • 2018-06-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    相关资源
    最近更新 更多