Batch Geocoding

Process a large number of addresses and save you up to 50% on your costs

Batch Geocoding was designed to save you time and decrease your expenses when processing a large number of addresses. You can easily convert blocks of addresses to latitude and longitude coordinates with one API call.

By getting our users geocoding requests as a batch, we can distribute our resources better to offer lower geocoding prices. As a result, processing one address with the batch geocoder costs 0.5 credits, while the regular geocoder requests cost 1 credit. So batch convert address to lat/long is 50% cheaper.

How Batch Geocoding service works

Batch geocoding is asynchronous. All you need to do is submit the addresses to convert to geographical coordinates and get results after some time.

To start batch geocoding process, you send a list of addresses to our servers using a simple HTTP POST request. You’ll see the job ID and URL to get the results when you get your response.

Make an HTTP GET to this URL, get back the results. If the job has not finished processing, this call will return "pending " in the status field. Once the job has finished, the response will contain the results including the longitude and latitude of each address.
In general, the processing time depends on the number of addresses. You may check the status of your batch geocoding tasks by calling the results URL. But you don't have to wait until the batcher finishes its job. It’s possible and even recommended to create multiple jobs and then pick up the results later. The results are available the next 24 hours after the job is completed.

Implementbatch geocode address tolat long

We provide a simple RESTful API, so you can quickly get your addresses geocoded. You can process them with no coding, for example with Postman or CURL.

You can also do it programmatically. Here is a code example of how this could be implemented.

Start Batch Geocoder job

To use the Geoapify API you will need to generate an API key. Find out how to create an API Key on the Getting Started page.
Crease an HTTP POST request on the "https://api.tmaps.tn/v1/batch/geocode/search " and send the addresses to geocode as the request body as JSON array:

const 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 "
];

const url = `https://api.tmaps.tn/v1/batch/geocode/search?apiKey=YOUR_API_KEY`;

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);
}
}).catch(err => console.log(err));

Get results - addresses, their geographical coordinates, address components

This job is in progress now. To get results, use the URL you received in the response. It may take several attempts to get your result:

function getBodyAndStatus(response) {
return response.json().then(responceBody => {
return {
status: response.status,
body: responceBody
}
});
}

function getAsyncResult(url, timeout /*timeout between attempts*/, maxAttempt /*maximal amount of attempts*/) {
return new Promise((resolve, reject) => {
setTimeout(() => {
repeatUntilSuccess(resolve, reject, 0) }, timeout);
});


function repeatUntilSuccess(resolve, reject, attempt) {
console.log("Attempt: " + attempt);
fetch(url)
.then(getBodyAndStatus)
.then(result => {
if (result.status === 200) {
resolve(result.body);
} else if (attempt >= maxAttempt) {
reject("Max amount of attempt achived ");
}
else if (result.status === 202) {
// Check again after timeout
setTimeout(() => {
repeatUntilSuccess(resolve, reject, attempt + 1)
}, timeout);
} else {
// Something went wrong reject(result.body)
}
})
.catch(err => reject(err)); };}

So now you can call the API and get results this way:

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 {
return getAsyncResult(`${url}&id=${result.body.id}`, 60 * 1000 /* 60 seconds */, 100).then(queryResult => {
console.log(queryResult);
return queryResult;
});
}
})
.catch(err => console.log(err));

Example of a result object

Say you want your users to be able to search for results near a location, for example:
Choose a city to show hotels nearby or Enter a postcode to show the closest shops or transportation stops
You can use the Address Autocomplete API with type parameters (such as type=city or type=postcode) to let your users choose a location.
Check our NPM Libraries that will help you add Address Autocomplete to your website or app.
Here's an example of a bounding box and coordinates that can be used to show results on a map and allow users to search for what they need:

0: {} 20 keys
query: {} 2 keys

ftext:"668 Cedar St, San Carlos, CA 94070, United States of America "

parsed: {} 7 keys

housenumber:"668 "
street:"cedar st "
postcode:"94070 "
city:"san carlos "
state:"ca "
country:"united states of america "
expected_type:"building "

Batch Geocoding parameters and features

Just like normal geocoding, batch geocoding accepts input parameters that serve for filtering or adjusting the output:

In addition, you can get results in JSON or CSV formats. Just add the format=csv to the resulting URL to get the results in a different form. All details can be found on our documentation page.

type

Location type, for example city, postcode, street, etc.;

filter

Filtering locations by geographical areas, for example, bounding box or country;

Bias

Preferring locations by proximity;

Lang

Lang - to get localized version of addresses.

FAQ

  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.
  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.

  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.
  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.

  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.
  • Create vector and raster maps you can use as a base-map layer for Leaflet, MapLibre GL, OpenLayers, QGIS, and other map libraries and GIS. Or use our Static Maps API to generate map images and map markers. Choose between different map styles and colors to match your app and website design.