首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >具有3个属性的对象数组,在google maps API中绘制路径时具有强行为

具有3个属性的对象数组,在google maps API中绘制路径时具有强行为
EN

Stack Overflow用户
提问于 2015-08-31 23:02:59
回答 1查看 30关注 0票数 0

我正试着在一条路线上画一个记号。标记移动,但路径未绘制(请按“显示”,然后按“动画”按钮)(我的代码jsfiddle

路线的坐标存储在对象“coord={lat:,lng:,stop:}”的数组中,该数组由下面的函数填充(我在代码中的第208行调用它):

代码语言:javascript
复制
function getLatLng(point, array) {

    //alert(MyArray.length);

    var lat = point.lat(),
        lng = point.lng();
    var tmp = MyArray[count].split(",");
    //  alert(  Math.abs(parseFloat(tmp[0]- lat)) )
    if (Math.abs(parseFloat(tmp[0] - lat)) < 0.00009 && Math.abs(parseFloat(tmp[1] - lng)) < 0.00009) {
        count++;
        array.push({
            "lat": lat,
            "lng": lng,
            "stop": 1
        });
        
    } else {

        array.push({
            "lat": lat,
             "lng": lng,
             "stop": 0
        });
      
    }
}

然后,我调用212行中的函数'h(coord)‘,该函数接受坐标数组作为参数。

代码语言:javascript
复制
function h(c) {
    //count++;
     alert( c.length +' '+ c);
    if (count == lengthCoord) {
        $(document).ready(function () {
            $("#btnSubmit").click(function () {
                autoRefresh(map, c);
            });
        });

    }


}

然后,我调用函数autoRefresh来设置标记的动画。

代码语言:javascript
复制
unction autoRefresh(map, f) {
    var i, route, marker;
    g = f;
    // alert(g[1]);
    route = new google.maps.Polyline({
        path: [],
        geodesic: true,
        strokeColor: '#FF0000',
        strokeOpacity: 1.0,
        strokeWeight: 2,
        editable: false,
        map: map
    });
    marker = new google.maps.Marker({
        map: map,
        icon: "http://maps.google.com/mapfiles/ms/micons/blue.png"
    });
    var i = 0,
        j = 0;

    fi(map, marker, g);

    function fi(m, mar, l) {
        // for (i = 0; i < l.length; i++) {
        var t = ["10", "200", "30 ", "40", "50", "60", "70", "80", "90", "100", "120", "130", "140", "150", ];
        k = i % 15;
        if (l[i].stop == 0) {
            //  alert(l[1].stop + '' + l[1 + 1].stop);
            setTimeout(function (coordo) {
                var latlng = coordo
              //  alert(latlng.lat);
                route.getPath().push(latlng);

                moveMarker(map, marker, latlng);
            }, 100 * i, l[i]);
            i++;
            fi(m, mar, l);
        } else {
            setTimeout(function (coordo) {
                var latlng = coordo
                route.getPath().push(latlng);

                moveMarker(map, marker, latlng);
                
            }, 100 * i, l[i]);



            setTimeout(fi, 600, m, mar, l);
            i++;
        }
    }

}

1个问题是:函数h()应该警告coord对象,但我得到了任何东西。

问题2:在第315行,函数autoRefresh获取对象坐标并将其存储在折线中以绘制路线。即使coord是对象{ lat:,mng:,stop }而不是(lat,lng)类型,它也会起作用。

3个问题:没有绘制路线。

我有点糊涂了。谁能给我解释一下问题出在哪里?

谢谢!

EN

Stack Overflow用户

发布于 2015-09-01 00:11:37

是的,因为你去掉了第189行directionsDisplay[instance].setDirections(response);

票数 0
EN
查看全部 1 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32314307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档