Page 1 of 1

How can I click on a map marker and have a info window appear?

Posted: Wed Jun 04, 2014 7:45 am
by adam griffin

I have on success after my list service execute that markers on my map are created. I am trying to have an info window appear when I click on the map marker. How can I do this? This my code so far, the marker are working perfectly.
var myOptions = {
zoom :3,
center: new google.maps.LatLng(37.63, -122.424),
mapTypeId: google.maps.MapTypeId.ROADMAP
};

var map = new google.maps.Map($('div[dsid="googlemap_8"]').get(0), myOptions);
//map = Appery('googlemap_8');

for(var i = 0; i < data.length;i++){

Code: Select all

 //alert(parseInt(data[i].Lat)); 

//San Francisco, with custom marker
var sfLatlng = new google.maps.LatLng(parseFloat(data.Lat) , parseFloat(data.Lng));
//var sfLatlng = new google.maps.LatLng(37.63+i4, -122.424+i3);
var marker = new google.maps.Marker({
position: sfLatlng,
map: map,
title: data.Username+"\n"+data.Post
});
var infowindow = new google.maps.InfoWindow({
content: data.Username+": \n"+data.Post
});

infowindow.open(Appery("googlemap_8").gmap, marker);
}


How can I click on a map marker and have a info window appear?

Posted: Wed Jun 04, 2014 10:16 am
by Evgene Karachevtsev

Hello Adam,

Please, look at this link, it should be helpful: https://developers.google.com/maps/do...


How can I click on a map marker and have a info window appear?

Posted: Wed Jun 04, 2014 12:51 pm
by adam griffin

I have a loop. How can I have each marker open info window when I click that particular marker??


How can I click on a map marker and have a info window appear?

Posted: Wed Jun 04, 2014 3:19 pm
by Evgene Karachevtsev

Adam,

You should define the function. for example, like this:

codefunction addInfowindow(map, marker,infowindow) {
google&#46;maps&#46;event&#46;addListener(marker, 'click', function() {
infowindow&#46;open(map,marker);
});} /code

and at the end of the loop add its call:

codeaddInfowindow(map, marker,infowindow);
} /code