caching google maps api v2
is it possible to cache geocodes on google maps api v2? because i need to get 6.5k marks on my map and with this script it would take around 20 minutes to load them all. and we don't want to use lat and lng if it isn't needed. and if it isn't possible does anyone know another way to load them faster? my knowledge of javascript isn't very good since this is my first script.
this is my code
<!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/1开发者_JAVA百科999/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>
Google's terms of service is pretty restrictive when it comes to caching data:
10.1.3 Restrictions against Data Export or Copying.
...
(b) No Pre-Fetching, Caching, or Storage of Content. You must not pre-fetch, cache, or store any Content, except that you may store: (i) limited amounts of Content for the purpose of improving the performance of your Maps API Implementation if you do so temporarily, securely, and in a manner that does not permit use of the Content outside of the Service; and (ii) any content identifier or key that the Maps APIs Documentation specifically permits you to store. For example, you must not use the Content to create an independent database of “places.”
You could possibly use a free geocoding service like the University of Southern California's webgis service to geocode all of your markers and store them. Then you could retrieve that data and plot it on a Google map.
Also, unless there is a specific reason to use Google Maps v2, I would recommend switching to Maps v3 since v2 is no longer supported.
精彩评论