Question

The problem is that the markers are not being displayed on the expected latlng but all 5 of them in Africa.Anyone can give me some advice or know why is this happening ? many thanks

function initialize() {
    var latlng = new google.maps.LatLng(52.474, -1.868);

    var myOptions = {
        zoom: 2,
        center: latlng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
    };

    var map = new google.maps.Map(document.getElementById("map"), myOptions);
    var image = 'marker1.png';

    var countries = [
        ['england', (51.508515 , -0.125487), 5],
        ['france', (46.227638 , 2.213749), 4],
        ['switcherland', (46.818188 , 8.227512), 3],
        ['italy', (41.871940 , 12.56738), 2],
        ['greece', (39.074208 , 21.824312), 1]
    ];

     for (var i = 0; i < countries.length; i++) {
         var marker = new google.maps.Marker({
             position: new google.maps.LatLng(countries[i][1],(countries[i][2],(countries[i][3],(countries[i][4],(countries[i][5]))))),
             map : map,
           //  icon: image,
             title: countries[i][0],
             zIndex:countries[i][5],
            animation: google.maps.Animation.DROP
         });
     }
}

window.onload = initialize;
Was it helpful?

Solution

You should not use parenthesis to define a point ( ).

This way should do it:

var countries = [
    ['england', 51.508515 , -0.125487, 5],
    ['france', 46.227638 , 2.213749, 4],
    ['switcherland', 46.818188 , 8.227512, 3],
    ['italy', 41.871940 , 12.56738, 2],
    ['greece', 39.074208 , 21.824312, 1]
];

Here is an example at jsFiddle.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top