是否有可能在谷歌地圖api v2上緩存地理編碼? ,因爲我需要在我的地圖上獲得6.5k的標記,而使用這個腳本需要大約20分鐘來加載它們。如果不需要,我們不想使用lat和lng。 如果這是不可能的,是否有人知道另一種方式來更快地加載它們?我的JavaScript知識不是很好,因爲這是我的第一個腳本。緩存谷歌地圖api v2
這是我的代碼
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"/>
<title>Google Maps JavaScript API Example</title>
<script src="http://maps.google.com/maps?file=api&v=2&key=ABQIAAAAjU0EJWnWPMv7oQ-jjS7dYxTPZYElJSBeBUeMSX5xXgq6lLjHthSAk20WnZ_iuuzhMt60X_ukms-AUg"
type="text/javascript"></script>
<script type="text/javascript">
//<![CDATA[
//load Google Map
function load() {
if (GBrowserIsCompatible()) {
var map = new GMap2(document.getElementById("map"));
var geocoder = new GClientGeocoder();
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
//hier .xml bestand plaatsen voor de adressen
GDownloadUrl("test.xml", function(data, responseCode) {
var xml = GXml.parse(data);
//store markers in markers array
var markers = xml.documentElement.getElementsByTagName("marker");
//loop voor het ophalen van markers
function placeMarker(i) {
//hier die dingen invullen waar hij naar moet zoeken in het .xml bestand
var address = markers[i].getAttribute("address"),
html = markers[i].getAttribute("html");
showAddress(map,geocoder,address,html);
if (++i <= markers.length) {
setTimeout(
function() {
placeMarker(i);
},
//snelheid van de loop hoe hoger het getal hoe langer de loop erover doet om rond te gaan (miliseconden)
210
);
}
}
placeMarker(0);
//Create marker and set up event window
function createMarker(point,html){
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function() {
marker.openInfoWindowHtml(html);
});
return marker;
}
//showAddress zorgt voor het omzetten van de adressen naar lengte en breedte graad
function showAddress(map,geocoder,address,html) {
geocoder.getLatLng(
address,
function(point) {
if (!point) {
alert(address + " niet gevonden, laad de pagina aub opnieuw als het adress van toepassing is.");
} else {
map.setCenter(point, 12);
var marker = createMarker(point,html+'<br/><br/>'+address);
map.addOverlay(marker);
}
}
);
}
}
); //close GDownloadUrl
} //close GBrowserIsCompatible
} //close load
//]]>
</script>
</head>
<body onload="load()" onunload="GUnload()">
<div id="map" style="width: 1000px; height: 700px"></div>
</body>
</html>