Hy i am unable to display multiple markers in Google Maps V3, i am getting the coordinates correctly but not displays on map. Also no errors in console
- map_items[0] = title
- map_items[1] = 55.153766, 11.909180
- map_items[2] = link
- map_items[3] = text
all of them appear correctly if i do an alert.
example
“Title”,”51.00150763193481, -2.5659284999999272″, “link”, “text”
function initialize() {
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 7,
center: new google.maps.LatLng(55.153766, 11.909180),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
for (var x = 0; x < temp.length; x++) {
if(temp[x][1]){
var map_items = temp[x];
var myLatlng = new google.maps.LatLng(map_items[1]);
var marker = new google.maps.Marker({
map: map,
position: myLatlng,
title: map_items[0]
});
google.maps.event.addListener(marker, 'click', function() {
infowindow.setContent('<div class="google_marker"><a href="'+map_items[2]+'">'+map_items[0]+'</a><br /><p>'+map_items[3]+'</p></div>');
infowindow.open(map, marker);
});
}
}
}
google.maps.LatLng() takes two parameters, not one, so:
though in fact, it would be better to use objects rather than an array in which each item contains different data types, for example:
and then you’d access it like this: