var Data =[
{address: "17 rue de l'Abreuvoir. Nantilly. 28260 La Chaussée d'Ivry"},
{address: "52 rue Ernestine 95100 Argenteuil"},
{address: "3 allée Baudelaire 59139 Wattignies"},
{address: "165, Petit chemin d'aix 13320 Bouc Bel Air"},
{address: "54 avenue Yolande d'Aragon 49100 ANGERS"},
{address: "John Doe, Le Rouho Guidel 56520"},
{address: "51100"},
{address: "21 rue du Docteur Gallet - 74000 Annecy"},
{address: "4 Impasse des Cigales, 26500 Bourg lès Valence"},
{address: "83140 SIX FOURS LES PLAGES"},
{address: "35 cours Vitton 69006 Lyon"},
{address: "7 rue lallier 75009"},
{address: "Paul Michel, Villa Pétricciù,Ghjassu Pétricciù, 20221.CERVIONE"}
]
var cityAndCountry = function(res){
var osmObj= res[0].address,
city=osmObj.town || osmObj.city || osmObj.county || '',
country=osmObj.country || '',
iso2 =osmObj.country_code || '';
var out = [ city, country, iso2];
return out
}
var latAndLon = function(res){
var lat= res[0].lat,
lon= res[0].lon;
var out = [lat,lon];
return out
}
var queryOsm = function(url) {
$.getJSON(url, function (data) {
data.length==0?
console.log(["","",""],data)
:console.log(cityAndCountry(data),latAndLon(data),data);
});
}
var delayedPing = function (i,data) {
// console.log(i, data.length)
var d = data[data.length-i];
if(d.address){
// placeAddressOnMap(gc, d.address, d.service||"", d.customer||"")
var url = 'https://nominatim.openstreetmap.org/search/'+d.address+'?format=json&addressdetails=1&limit=1';
queryOsm(url)
} else { console.log(["","","",d.address]) }
var delay = 1000+200*Math.random();
if (--i > 0) { setTimeout(function () { delayedPing(i,data); }, delay); }
}
delayedPing(Data.length,Data);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>