Batch Geocoding API
Async call for Batch Geocoding API example
by Geoapify
JavaScript
var data = [
"668 Cedar St, San Carlos, CA 94070, United States of America",
"545 Southwest Taylor Street, Portland, OR 97204, United States of America",
"1415 Southwest Park Avenue, Portland, OR 97201, United States of America",
"1019 Southwest Morrison Street, Portland, OR 97205, United States of America",
"400 Southwest 6th Avenue, Portland, OR 97204, United States of America",
"1972 Northwest Flanders Street, Portland, OR 97209, United States of America",
"1150 Northwest Quimby Street, Portland, OR 97209, United States of America",
"2116 Northwest 20th Avenue, Portland, OR 97209, United States of America",
"200 East 13th Street, Vancouver, WA 98660, United States of America",
"1108 Main St, Vancouver, WA 98660, United States of America",
"410 West Mill Plain Boulevard, Vancouver, WA 98660, United States of America",
"900 W Evergreen Blvd, Vancouver, WA 98660, United States of America",
"2008 Simpson Ave, Vancouver, WA 98660, United States of America"
];
// The API Key provided is restricted to JSFiddle website
// Get your own API Key on https://myprojects.geoapify.com
var myAPIKey = "6dc7fb95a3b246cfa0f3bcef5ce9ed9a";
var url = `https://api.geoapify.com/v1/batch/geocode/search?apiKey=${myAPIKey}`;
fetch(url, {
method: 'post',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json'
},
body: JSON.stringify(data)
})
.then(getBodyAndStatus)
.then((result) => {
if (result.status !== 202) {
return Promise.reject(result)
} else {
console.log("Job ID: " + result.body.id);
console.log("Job URL: " + result.body.url)
return getAsyncResult(`${url}&id=${result.body.id}`, 1000, 100).then(queryResult => {
console.log(queryResult);
return queryResult;
});
}
})
.catch(err => console.log(err));
function getBodyAndStatus(response) {
return response.json().then(responceBody => {
return {
status:...