I have a function that loops through an XML file of marker data. I need to set my map so that the last marker in the loop is zoomed in.
var image = 'images/Icon.png'
var map = new google.maps.Map(document.getElementById("map_canvas"), myOptions);
downloadUrl("phpsqlajax_genxml4.php", function(data) {
var markers = data.documentElement.getElementsByTagName("marker");
for (var i = 0; i < markers.length; i++) {
var latlng = new google.maps.LatLng(parseFloat(markers[i].getAttribute("lat")),
parseFloat(markers[i].getAttribute("lng")));
var marker = createMarker(markers[i].getAttribute("name"), markers[i].getAttribute("ft"), markers[i].getAttribute("inch"), markers[i].getAttribute("lbs"), markers[i].getAttribute("oz"), markers[i].getAttribute("date"), markers[i].getAttribute("pic"), latlng);
}
});
function createMarker(name, ft, inch, lbs, oz, date, pic, latlng) {
var marker = new google.maps.Marker({position: latlng, map: map, icon: image});
var html = "<table border='0'>" +
"<tr>" +
"<td width='150'>" + "<strong>" + name + "<br>" + ft + " " + inch + " " + lbs + " " + oz + "</strong><br>" + date + "</td>" +
"<td width='100'>" + '<img src="image.jpg?width=80&height=80&cropratio=1:1&image=' + pic +'"/>' + "</td> </tr> </table>";
google.maps.event.addListener(marker, "clic开发者_如何学运维k", function() {
if (infowindow) infowindow.close();
infowindow = new google.maps.InfoWindow({content: html});
infowindow.open(map, marker);
});
return marker;
}
try to use this to center the marker
map.setCenter(new GLatLng(parseFloat(markers[0].getAttribute("lat")),
parseFloat(markers[0].getAttribute("lng"))),3);
精彩评论