Polyline()不接受Google Maps API MVCArray [英] Google Maps API MVCArray isn't being accepted by Polyline()

查看:105
本文介绍了Polyline()不接受Google Maps API MVCArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的代码来绘制标记,然后将它们与折线连接在一起,但是我要与折线一起使用的MVCArray不起作用(并且不起作用"是指折线不起作用)正在绘制).这是我的代码:

I have a simple code plotting markers and then connecting them together with a polyline but the MVCArray I am trying to use with the Polyline isn't working (and by "isn't working" I mean that the Polyline isn't being plotted). Here is my code:

$(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}

推荐答案

我能够通过设置100ms超时来解决我的问题,以防止在地理编码器完成地理编码之前将MVCArray发送到Polyline.

I was able to solve my issue by setting a 100ms timeout to prevent the MVCArray from being sent to Polyline until the geocoder had finished geocoding.

这篇关于Polyline()不接受Google Maps API MVCArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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