所以现在在 V3 中,现在我无法让标记出现!在警报中获得正确的结果。
var infowindow;
var map;
var latlng;
var lat;
var lng;
function initialize() {
var myLatlng = new google.maps.LatLng(51.949344,7.846573);
var myOptions = {
zoom: 7,
center: myLatlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
downloadUrl("example.xml", function(data) {
var markers = data.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var address = markers[i].getAttribute("address");
var geocoder = new google.maps.Geocoder();
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
lat = parseFloat(results[0].geometry.location.lat());
lng = parseFloat(results[0].geometry.location.lng());
latlng = new google.maps.LatLng(lat,lng);
alert('Geocode succesful ' + latlng);
} else {
alert("Geocode was not successful for the following reason: " + status);
}
});
var marker = createMarker(markers[i].getAttribute("name"), latlng);
}
});
}
function createMarker(name, latlng) {
var marker = new google.maps.Marker({position: latlng, map: map});
google.maps.event.addListener(marker, "click", function() {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({content: name});
infowindow.open(map, marker);
});
return marker;
}
这个 XML 布局:
<markers>
<marker address="XXXXX 2, Rotterdam" name="Info">
<marker address="XXXXX 25, Amsterdam" name="Info2">
<marker address="XXXX 52, Rotterdam" name="Info3">
</markers>
希望您能提供帮助,如果这是一个非常简单的解决方案,请原谅,但我对此有点陌生。
谢谢,E