Dette script kan geocode mange adresser på én gang med et delay på 1,75 sek. som kan justeres - udskyld for signaturen:
<!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" xmlns:v="urn:schemas-microsoft-com:vml">
<head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Google Maps</title>
<script src="
http://maps.google.com/maps?file=api&v=2&key=ABQIAAAA3qyl_FEhGYSK9pSjzs-SVBRRmxvsDchdZPynv1Lw2iDuExpu_hRedE5TdRiy6czrOuJj2d3qm2FCLA" type="text/javascript"></script>
</head>
<body onunload="GUnload()">
<div id="message"><?xml version="1.0" encoding="UTF-8"?><br><markers><br></div>
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
// ====== Create a Client Geocoder ======
var geo = new GClientGeocoder();
// ====== Array for decoding the failure codes ======
var reasons=[];
reasons[G_GEO_SUCCESS] = "Success";
reasons[G_GEO_MISSING_ADDRESS] = "Missing Address: The address was either missing or had no value.";
reasons[G_GEO_UNKNOWN_ADDRESS] = "Unknown Address: No corresponding geographic location could be found for the specified address.";
reasons[G_GEO_UNAVAILABLE_ADDRESS]= "Unavailable Address: The geocode for the given address cannot be returned due to legal or contractual reasons.";
reasons[G_GEO_BAD_KEY] = "Bad Key: The API key is either invalid or does not match the domain for which it was given";
reasons[G_GEO_TOO_MANY_QUERIES] = "Too Many Queries: The daily geocoding quota for this site has been exceeded.";
reasons[G_GEO_SERVER_ERROR] = "Server error: The geocoding request could not be successfully processed.";
reasons[403] = "Error 403: Probably an incorrect error caused by a bug in the handling of invalid JSON.";
// ====== Geocoding ======
function getAddress(search, next) {
geo.getLocations(search, function (result)
{
// If that was successful
if (result.Status.code == G_GEO_SUCCESS) {
// Lets assume that the first marker is the one we want
var p = result.Placemark[0].Point.coordinates;
var lat=p[1];
var lng=p[0];
// Display the results in XML format
var xml = ' <marker address="' + search + '" lat="' +lat+ '" lng="' +lng+ '"><br>';
document.getElementById("message").innerHTML += xml;
}
// ====== Decode the error status ======
else {
var reason="Code "+result.Status.code;
if (reasons[result.Status.code]) {
reason = reasons[result.Status.code]
}
var xml = ' <marker address="' + search + '" error="' +reason+ '"><br>';
document.getElementById("message").innerHTML += xml;
}
next();
}
);
}
// ======= An array of locations that we want to Geocode ========
var addresses = [
"1060 West Addison Street, Chicago, IL",
"99, rue de Rivoli, Paris 75001",
"Oder, DE",
"Piazza della Scala, Milano 20121",
"London, UK",
"1600 Pennsylvania Avenue, Washington, DC",
"A totally bogus address"
];
// ======= Global variable to remind us what to do next
var nextAddress = 0;
// ======= Function to call the next Geocode operation after a delay of 1.725 sconds
function theNext() {
if (nextAddress < addresses.length) {
setTimeout('getAddress("'+addresses[nextAddress]+'",theNext)', 1725);
nextAddress++;
} else {
document.getElementById("message").innerHTML += "</markers>";
}
}
// ======= Call that function for the first time =======
theNext();
}
// display a warning if the browser was not compatible
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
//]]>
</script>
</body>
</html>