Searching Addresses in Bulk
If large amounts of address data has to be geocoded, it can be useful to group and process these addresses in larger groups. Therefor the xlocate service provides the searchLocationsInBulk operation.
Benefits
Geocoding several addresses with one request has the following benefits:
- Due the less protocol overhead, the network traffic is reduced.
- The possibility to use a asynchronous implementation of the service operation.
Prerequisites
Check if the following prerequisites are fulfilled before you start with the use case:
- Installed and licensed PTV xLocate service
- Installed PTV map data
Programming Guide
There are two different ways to geocode addresses in bulk. The first one uses structured addresses:
// Search for the addresses. xlocate.searchLocationsInBulk({ "$type": "SearchByAddressBulkRequest", "addresses": [{ "country": "Lëtzebuerg", "postalCode": "9151", "city": "Eschduerf", "street": "Op der Heelt" }, { "country": "Lëtzebuerg", "postalCode": "9160", "city": "Ingeldorf", "street": "Rue Longchamp" }] }, searchCompleted); // Process the results. function searchCompleted(response, exception) { if (response.responseItems instanceof Array) { print('Geocoding succeeded and results for ' + response.responseItems.length + ' addresses found.'); } else { print('Geocoding failed.'); } }Alternatively, it is possible to pass the addresses as a formless string:
// Search for the addresses. xlocate.searchLocationsInBulk({ "$type": "SearchByTextBulkRequest", "texts": [ "Wenkel 11 Remerschen", "3350 Leudelange, Rue du Cimetiere 35", "Rue de Mamer, 8390 Kehlen" ]}, searchCompleted); // Process the results. function searchCompleted(response, exception) { if (response.responseItems instanceof Array) { print('Geocoding succeeded and results for ' + response.responseItems.length + ' addresses found.'); } else { print('Geocoding failed.'); } }NOTE: Geocoding more 1000 addresses with one request may require increased xServer memory settings.