谷歌地图多个标记

时间:2014-12-13 17:18:16

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

我尝试按坐标添加多个标记。但我看不出任何结果。这是js: 在我的页面上,我收到了这个JS代码:

function initialize() {
        var markers = [["\u041a\u0438\u0435\u0432",50.401515322782,30.5859375],["\u0425\u0430\u0440\u044c\u043a\u043e\u0432",49.922935454496,36.2548828125],["\u041a\u0438\u0435\u0432",50.457504020421,30.498046875],["\u041a\u0438\u0435\u0432",50.457504020421,30.498046875],["\u0414\u043d\u0435\u043f\u0440\u043e\u0432\u0441\u043a\u0438\u0439 \u0440\u0430\u0439\u043e\u043d",50.457504020421,30.6298828125]];
        var myLatlng = new google.maps.LatLng(37.4419, -122.1419);
        var myOptions = {
            zoom: 13,
            center: myLatlng,
            mapTypeId: google.maps.MapTypeId.ROADMAP
        };
        var map = new google.maps.Map(document.getElementById("googleMap"), myOptions);
        for (var i = 0; i < markers.length; i++) {
            new google.maps.Marker({
                "position": new google.maps.LatLng(markers[i][1], markers[i][2]),
                "map": map
            });
        }
    }
    google.maps.event.addDomListener(window, 'load', initialize);

1 个答案:

答案 0 :(得分:1)

你的javascript变量locs是一个字符串,而不是一个数组,当你这样分配它时:

var locs = '{{ locs|json_encode|raw }}';

但是你试着将它当作一个带循环的数组来对待它。我认为你应该能够做到这一点:

var locs = {{ locs|json_encode|raw }};