I know, it is a recurrent but... I have a big problem with my multiple markers : all of them have the same title and the same infowindow content.
I've searched on many websites, but I didn't find where is the problem in my code.
I hope you'll be able to help me (I am sure it is the case !)
This is my code :
<script type="text/javascript">
var map;
var geocoder;
$(document).ready(function() {
initializeMap();
});
function initializeMap() {
var people = [{"userid":"47","lastname":"lastname1","firstname":"firstname1","address":"SomeAddress","phone1":"00000000000","phone2":"","email":"[email protected]"},{"userid":"42","lastname":"lastname2","firstname":"firstname2","address":"SomeAddress2","phone1":"0","phone2":"0","email":"[email protected]"}];
var center = new google.maps.LatLng(40.667, -73.833);
var myOptions = {
zoom: 8,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder = new google.maps.Geocoder();
for (i = 0; i < people.length; i++) {
var p = people[i];
geocoder.geocode( { 'address': p["address"]}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map:map,
draggable:false,
animation: google.maps.Animation.DROP,
title:p["lastname"] + " " + p["firstname"],
position: results[0].geometry.location
});
var myWindowOptions = {
content:
'<h3>'+p["lastname"] + " " + p["firstname"]+'</h3>'+
'<p>'+p["address"]
};
var myInfoWindow = new google.maps.InfoWindow(myWindowOptions);
google.maps.event.addListener(marker, 'click', function() {
myInfoWindow.open(map,marker);
});
});
}
}
</script>
I realy hope somebody can show me my mistake(s) and thanks a lot for help !!
No, I really don't understand,
It should be something I didn't see in my code :
<script type="text/javascript">
var map;
var geocoder;
$(document).ready(function() {
initializeMap();
});
function initializeMap() {
var people = [{"userid":"47","lastname":"lastname1","firstname":"firstname1","address":"SomeAddress","phone1":"00000000000","phone2":"","email":"[email protected]"},{"userid":"42","lastname":"lastname2","firstname":"firstname2","address":"SomeAddress2","phone1":"0","phone2":"0","email":"[email protected]"}];
var center = new google.maps.LatLng(50.833, 25.000);
var myOptions = {
zoom: 8,
center: center,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
geocoder = new google.maps.Geocoder();
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < people.length; i++) {
alert(people[i]['address']);
geocoder.geocode( { 'address': people[i]["address"]}, function(results, status) {
marker = new google.maps.Marker({
position: results[0].geometry.location,
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent('<h3>'+people[i]["lastname"] + " " + people[i]["firstname"]+'</h3>');
infowindow.open(map, marker);
}
})(marker, i));
});
}
}
</script>
Thanks for help !! :)
See Question&Answers more detail:
os