ggmap icon indicating copy to clipboard operation
ggmap copied to clipboard

Geocoding fails when curl::curl_fetch_memory(url, handle = handle) fails in httr::GET()

Open lorenzwalthert opened this issue 4 years ago • 1 comments

I was geocoding thousands of observations and in the middle of the process, it failed like this:

geocoded <- geocode(subset$address)
Source : https://maps.googleapis.com/maps/api/geocode/json?address=KOMPLEK+TOMANG+ELOK+JLN.+GATOT+SUBROTO+MEDAN+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jl.Karya+Tani+Gg+Sementara+No.8+Medan+Johor,+Medan+Dekat+dengan+Asrama...&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Geocoding "Jl.Karya Tani Gg ..." failed with error:

Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jalan+Bakti+Luhur,+Komplek+Millenium+Townhouse+1,+Dwi+Kora,+Medan+Helvetia+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=Jalan+Datuk+Rubiah+Titi+Papan+Marelan+Medan+Medan&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY
Source : https://maps.googleapis.com/maps/api/geocode/json?address=jalan+bajak+1+,+akses+bisa+masuk+dari+sm+raja+sebelah+dinas+kehutanan+atau+akses+bisa+masuk+dari+stm+suka+iklas+alfalah+dan...&key=xxx-gHK2yiLHpsTi0WyX3USVv0ZzfY

Error in curl::curl_fetch_memory(url, handle = handle) : 
  Operation was aborted by an application callback

I think it the problem is that this call to httr::GET() is not wrapped in a tryCatch() or similar. Then, the error message seems to come from here in the httr source code. Suggestion to fix this:

Wrap the httr::GET() call referenced above into tryCatch() (or rlang::with_handlers()) and return the default for the failed output with return_failed_geocode(). I can provide a PR if interested.

lorenzwalthert avatar Oct 06 '20 09:10 lorenzwalthert

Hi, I got an error also caused by curl::curl_fetch_memory(). Similarly, I was geocoding thousands of observations and in the middle of the processes, mine failed as follows:

Error in `map()`:
In index: 11566.
Caused by error in `curl::curl_fetch_memory()`:
Timeout was reached: [maps.googleapis.com] Resolving timed out after 10012 milliseconds

So far, I have not been successful in finding the root of the problem. Therefore, I would appreciate any help!

maxl-amberg avatar Jun 16 '23 16:06 maxl-amberg