Hi,
How do I give the markers on my Google map a title ? I have several locations on each database, all of which are appearing, but I need to label them in order to differentiate between them.
Thanks.
This topic is no longer open for comments or replies.
-
Hi Leon,
Here is how to do it with JS code in marker constructor:
var marker = new google.maps.Marker({
position: new google.maps.LatLng(49, 49),
map: map,
draggable: true,
//Here is how to add title to the marker.
title: "title custom text"
});
Regards. -
-
Thanks.
Should this be added as a new script or added to my location helper JS ?- view 2 more comments
-
-
-
Hi Leon,
it's unclear now what you want do to. Please specify it in details.
Regards. -
-
Hi Yurii,
I have 6 map markers on one map and 5 on another - I am trying to find out how to make an information window appear when each marker is clicked on. Can you advise?
Thanks,
Leon -
-
-
Hi Leon,
For these goals you need to use JS closures.
Here is code example of what you need:
//Were "multiGoogleMap" is map component name.
var map = Appery("multiGoogleMap").options.mapElement.gmap('get', 'map');
//Create infowindow.
var infowindow = new google.maps.InfoWindow({
content: 'test content',
maxWidth: 320
});
var CreateMarker = function(data){
var marker = new google.maps.Marker({
position: new google.maps.LatLng(data.lat, data.long),
map: map,
draggable: true,
icon: "http://i.imgur.com/QtWkT.png",
title: data.location
});
//Add event handler and open infoWindow
google.maps.event.addListener(marker, 'click', function() {
//Set content for infowindow.
infowindow.setContent('Content of + ' + data.location + '');
//Open infowindow.
infowindow.open(map, marker);
});
};
for (var i = 0; i < locationHelper.aLocations.length; i++)
//In this function you should to pass latitude, longitude and text to display in infowindow.
CreateMarker({lat: locationHelper.aLocations[i][0], long: locationHelper.aLocations[i][1], location: locationHelper.aLocations[i][2]});
Regards. -
-
Hi Yuri,
Thanks for the code. I know how to create the script but have no idea as to how to link it to my map so it actually works - will I need to create a new event in the data section on the page my map is located on? -
-
Hi Leon,
It very depends on what you want to implement.
For example if you have some service, result of from you willing to populate markers - you can add "success" event handler for your service datasource.
Also you can add "page load" event handler if you want to populate markers from static(constant) data.
If you need more details you should provide us screen shots with your ui and describe them.
Regards. -
-
-
-
Hi Deon,
Provided above code do what you described:
So here is part of this code:
google.maps.event.addListener(marker, 'click', function() {
alert("marker click");
//Set content for infowindow.
infowindow.setContent('Content of + ' + data.location + '');
//Open infowindow.
infowindow.open(map, marker);
});
This code set "click" event handler and by action on it - open infowindow with content.
Regards. -