简体   繁体   中英

Google map multiple markers

I try to add multiple markers to map by coordinates. But I cant see any results. Here is js: On my page I recieved this JS code:

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);

Your javascript variable locs is a string, not an array, when you assign it like so:

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

But then you try to treat it as if it was an array with your loop. I think you should be able to do this instead:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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