restgetgeocodinghere-apihere-maps-rest

What is the most efficient way to query multiple values via HERE API REST query?


Question:

How do I efficiently handle multiple location requests to the HERE API?

I am new to GET requests and REST generally, but I have a need to get location data, and I'm experimenting with the HERE API. I'm doing this in R, but that fact is irrelevant to my question.

This works:

library(httr)
library(jsonlite)

HERE_API_KEY <- #REMOVED#
url <- "https://geocode.search.hereapi.com/v1/"
zip <- 18615
country <- "United+States"

theRequest <- paste0(url,"geocode?qq=postalCode=",zip,";country=",country,"&apiKey=",HERE_API_KEY)

theResponse <- GET(theRequest)

I get a Status 200 message and the data content -- no issues there.

What I want:

The above example is just one location, but I have a list of several thousand locations I need to look up, eventually trying to determine routing distance between two points in the location data set.

I can create a loop and submit a request for each location one at a time as demonstrated above, but since I have a bunch, I wonder if there is a preferred method to submit the list of locations in one single call (or break it up in groups?) that would be nicer to the the HERE API and efficiently get the data. Stabbing in the dark, I tried this test for 3 locations:

theRequest <- "https://geocode.search.hereapi.com/v1/geocode?qq=postalCode=18615;country=United+States&qq=postalCode=L4T1G3;country=Canada&qq=postalCode=62521;country=United+States&apiKey=#REMOVED#"

But it didn't work. Maybe this is not possible and I just don't understand REST, but I want to handle multiple requests as efficiently as possible -- both for myself and for the HERE API service. Thank you in advance.


Solution

  • If you want to use the HERE Geocoding and Search API, looping through your data to send individual GET requests for each address is a perfectly valid approach, just make sure that you don't exceed the maximum allowed number of requests per second (RPS) for the plan you have (5 RPS for the Geocoding and Search API in the Freemium Plan, for example); otherwise your queries will result in error code 429 "Too Many Requests" and you'll have to send them again.

    Alternatively, you can use the HERE Batch Geocoder API, which is designed to process large datasets (up to 1 million records for geocoding or reverse geocoding) with a single API call. Using this service consists of 3 steps:

    1. Send a single POST request with all the data you want to geocode or reverse geocode.
    2. Call the status endpoint to monitor the status of the job you submitted. You might want to make this type of call periodically until the response indicates that your job is complete and your output is ready to be downloaded.
    3. Download your results.

    Here's an example of how to use this service; notice that this API supports POST requests instead of GET.