Views:

PTV Developer does not offer a special method for batch geocoding.

We recommend calling the method mulitple times if you want to geocode more than one address.

The following code sample shows a Javascript method that contains an array with several input addresses.

When calling the service for each element of this array the results for the corresponding addresses can be seen in the console log of the browser.

You can call this function from any website and replace the value for api_key with a valid key from your account.

 

function searchAddress(){
        var adresses = [ {value:"Karlsruhe, Stuttgarter Str. 2"}, {value:"Albert-Einstein-Allee, Ulm"}, {value:"Berlin, Alexanderplatz"}, {value:"München, Arcistrasse"}  ];
        const locationURL =  "https://api.myptv.com/geocoding/v1/locations/by-text?searchText=";
        var s;


        for(let i=0; i<adresses.length; i++){
             s  = locationURL + adresses[i].value;
             console.log(s);
            fetch(
              s, {
                
                method: "GET",
                headers: {
                    "apiKey": api_key,
                    "Content-Type": "application/json"
                }
            }
                
            )
            .then(response => response.json()
            .then(result => {

                for(let i=0; i<result.locations.length; i++){
                    console.log(result.locations[i]);
                }    
               ;
            }))
            .catch(ex => {
                alert(ex.message);
            });
        }   
    }

 

 

Related Products: PTV Developer