I have a google map with kmz overlay on my site:
<script type="text/javascript">
<!--
var geocoder;
var map;
var overlayXml;
function initialize() {
// if (GBrowserIsCompatible()) {
geocoder = new google.maps.Geocoder();
var latlng = new google.maps.LatLng(25,-24);
var myOptions = {
zoom: 2,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
}
map = new google.maps.M开发者_StackOverflowap(document.getElementById("map_canvas"), myOptions);
// map.setUIToDefault();
var ctaLayer = new google.maps.KmlLayer('http://linktothe/data.kmz');
ctaLayer.setMap(map);
// }
}
function codeAddress() {
var address = document.getElementById("address").value;
geocoder.geocode( { 'address': address}, function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
map.setZoom(10);
} else {
alert("Could not navigate to location. Reason: " + status);
}
});
}
//-->
</script>
</head>
<body onload="initialize()" onunload="GUnload()">
etc.
There are two problems:
1) When I first go to the page, the overlay is not showing. I have to refresh the page for it to show. I have no idea why that happens. Maybe it's because the overlay is very big (about 3500 markers)? I believe I have already exhausted my options (the file used to be >1MB before I switched to the compressed kmz version).
2) Once I get the overlay to load, it has an unwanted behavior. The map is zoomed out from its initial position to show the whole overlay. How can I control this behavior?
精彩评论