JSFiddle - React, Tailwind, and code Playground
HTML
<h3>Geocoding without geocoder</h3>
<p>Get many locations at once</p>
<button>Start</button>
<div id="results"></div>
JavaScript
var apiURL = "http://maps.googleapis.com/maps/api/geocode/json?address=";
// $.getJSON() is a jQuery method that can replace the ajaxRequest() from AM1
var addresses = ['Boston', 'Wellesley', 'Natick', 'Chicago', 'Detroit', 'Vienna', 'Berlin', 'Rome', 'Paris', 'London', 'Dublin', 'Spain', 'Italy', 'Germany', 'China', 'India', 'Japan', 'Australia', 'Seattle', 'Montreal'];
//alert("Addresses: " + addresses.length);
function sendWithDelay(i){
setTimeout(function(){
$.getJSON(apiURL+encodeURI(addresses[i]), showResult);},
i*1000);
}
$("button").click(function(){
for (var i in addresses){
sendWithDelay(i);
}
});
// callback function
function showResult(response){
//console.log("response from API ", response);
if (response.status == "OK") {
$("<p>").text(response.results[0].formatted_address)
.appendTo("#results");
var locObj = response.results[0].geometry.location;
$("<p>").text(locObj.lat + "; " + locObj.lng)
.appendTo("#results");
}
}