dkahle / ggmap

A package for plotting maps in R with ggplot2
763 stars 231 forks source link

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

Open lorenzwalthert opened 3 years ago

lorenzwalthert commented 3 years ago

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.

maxl-amberg commented 1 year ago

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!