简体   繁体   English

在Google地图中添加for循环迭代和绘制折线的最佳方法?

[英]Best way to add for loop to iterate and draw polylines in google maps?

I have a below function which displays a map. 我有一个下面的功能,显示地图。 but how to set the loop in .addPolylines() function. 但是如何在.addPolylines()函数中设置循环。 I get proper latitude & longitude but I added a loop but it has displayed a blank map. 我得到适当的纬度和经度,但添加了一个循环,但显示空白地图。 can you help me to fix it? 你能帮我解决吗?

create_map(<%= raw @boundary_points.to_json %>);

function create_map(boundary_points) {
    var handler = Gmaps.build('Google');

    handler.buildMap({
        internal: {
            id: 'geolocation'
        }
    }, function() {

        for (i = 1; i < boundary_points.length; i++) {
            var ls = boundary_points[i].trim().split(" ");
        }

        var polylines = handler.addPolylines(
            [
                [
                    for (i = 1; i < boundary_points.length; i++) {
                        var ls = boundary_points[i].trim().split(" "); {
                            lat: ls[0],
                            lng: ls[1]
                        },
                    }

                ]
            ], {
                strokeColor: '#FF0000'
            }
        );
        handler.bounds.extendWith(polylines);
        handler.fitMapToBounds();
        handler.getMap().setZoom(15);
        alert(boundary_points);
    });
}

 // // This is a sample array with points // var points = ["45.678295 -121.603813", "45.678196 -121.603607"]; // // This should be used for handler.addPolylines call // var polylines = []; for (i = 0; i < points.length; i++) { var ls = points[i].trim().split(" "); polylines[i] = {}; polylines[i]["lat"] = parseFloat(ls[0]); polylines[i]["lng"] = parseFloat(ls[1]); } console.log(polylines); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM