我有一个带有标签的自定义标记,我想将标签放置在标记的中心。我尝试填充,边距和偏移量仍然无法正常工作。我该怎么做?
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
});
}
答案 0 :(得分:1)
检查有效的标签来源
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,
});
}
答案 1 :(得分:1)
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"
},
});
}