I have a custom marker with a label I want to position the label in the center of the marker. I tried padding, margin and offset still it wont work. How can I do it?
var image = './stylesheet/images/map-marker/activity-marker.png';
for(var i = 0; i < data.length; i++) {
var coords = data[i].GPSCoordinates.split(',');
var position = new google.maps.LatLng(coords[0], coords[1]);
var labels = "" + (i + 1);
addMarker(position, map, labels);
}
function addMarker(location, map,label) {
var marker = new google.maps.Marker({
position: location,
map: map,
label: {
text: label,
fontSize: "12px",
color: "#e74c3c",
fontFamily: "montserrat"
},
icon: image
});
}
check for a valid labelOrigin
function addMarker(location, map,label) {
myIcon = {
url: './stylesheet/images/map-marker/activity-marker.png',
text: label,
fontSize: "12px",
color: "#e74c3c",
fontFamily: "montserrat"
size: new google.maps.Size(32, 38),
scaledSize: new google.maps.Size(32, 38),
labelOrigin: new google.maps.Point(9, 9),
};
var marker = new google.maps.Marker({
position: location,
map: map,
icon: myIcon,
});
}
var image = './stylesheet/images/map-marker/activity-marker.png'; for(var i = 0; i < data.length; i++) { var coords = data[i].GPSCoordinates.split(','); var position = new google.maps.LatLng(coords[0], coords[1]); var labels = "" + (i + 1); addMarker(position, map, labels); } function addMarker(location, map,label) { var marker = new google.maps.Marker({ position: location, map: map, icon: { labelOrigin: new google.maps.Point(9, 9), // Set this value for position of lable on marker... url: './stylesheet/images/map-marker/activity-marker.png' }, label: { text: label, fontSize: "12px", color: "#e74c3c", fontFamily: "montserrat" }, }); }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.