有几个类似的问题和答案,但我确实无法弄清楚!因此,我使用了两个不同的图标(customIcons),但由于默认设置“锚点位于图像底部的中心点”,它们在地图上的放置略有不正确。(请参阅https://developers.google.com/maps/documentation/javascript/reference#MarkerOptions)。我知道我必须更改该默认功能,但不知道如何更改。我定义自定义图标
var markers = [];
var infoWindow;
var customIcons = {
recent: {icon: 'http://www.herpetofauna-nrw.de/Fundmeldungen/blauer_Punkt.png'},
historisch: {icon: 'http://www.herpetofauna-nrw.de/Fundmeldungen/roter_Punkt.png'}
};
后来我使用:
downloadUrl("auswertung.xml?ienocache="+new Date().getMilliseconds(), function(data){
var xml = data.responseXML;
var markers = xml.documentElement.getElementsByTagName("marker");
var bounds = new google.maps.LatLngBounds();
for (var i = 0; i < markers.length; i++) {
var Art = markers[i].getAttribute("Art");
var type = markers[i].getAttribute("Stichjahr");
var Jahr = markers[i].getAttribute("Jahr");
var MTBNr = markers[i].getAttribute("MTBNr");
var latlng = new google.maps.LatLng(
parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var html =
"<b>" + "Art: " + "</b>" + Art + " <br/>" +
"<b>" + "MTB: " + "</b>" + MTBNr + "<br/>" +
"<b>" + "Funddatum: " + "</b>" + Jahr + "<br/>";
var icon = customIcons[type] || {};
var marker = new google.maps.Marker({
map: map,
position: latlng,
icon: icon.icon
});
但是当我使用“var icon = customIcons[type] || {};” 我不知道在哪里放置必要的选项“new google.maps.Point(0,0)”,例如:
var image = new google.maps.MarkerImage('XXX.png', // The image size
new google.maps.Size(44, 46), // The origin
new google.maps.Point(0,0), // The anchor
new google.maps.Point(22, 23));
有人可以帮忙吗?提前谢谢了!