2

I am trying to calculate driving times and distances for a few thousands of origins and destinations. However, my company firewall appears to be causing some problems when using googleway or gmapsdistance packages, but works perfectly fine for the ggmap package. For example:

# Library packages
library(ggmap)
library(googleway)
library(gmapsdistance)

# Set my origin and destination places
org   <- "waco, texas"
dest  <- "houston, texas"

# Register my key (note: insert your own Google key)
myKey <- "insert_key"
register_google(key = myKey)

# Calculate distance
mapdist(from = org, to = dest, mode = "driving")

# Source : https://maps.googleapis.com/maps/api/distancematrix/json?
# origins=waco,+texas&destinations=houston,+texas&key=xxx&mode=driving
# Error in curl::curl_fetch_memory(url, handle = handle) : 
#  Timeout was reached: Connection timed out after 10000 milliseconds

I have been able to bypass this by using solutions stated in other questions and by using curl package, for example:

library(curl)

# Get ie proxy
proxyPort <- ie_get_proxy_for_url()

# Split the string to feed the proxy and port arguments
proxyURL  <- strsplit(proxyPort, ":")[[1]][1]
portUsed  <- as.integer(strsplit(proxyPort, ":")[[1]][2])

# Set configuration
set_config(use_proxy(url=proxyURL, port = portUsed), override = TRUE)

# Register my key
register_google(key = myKey)

# Calculate distance
mapdist(from = org, to = dest, mode = "driving")

# Source : https://maps.googleapis.com/maps/api/distancematrix/json?# origins=waco,+texas&destinations=houston,+texas&key=xxx&mode=driving
# A tibble: 1 x 9
#  from        to                  m    km miles seconds minutes hours mode   
#  <chr>       <chr>           <int> <dbl> <dbl>   <int>   <dbl> <dbl> <chr>  
# 1 waco, texas houston, texas 297148  297.  185.   10235    171.  2.84 driving

You can see that this works!

However, the equivalent functions for the googleway and gmapsdistance package seem to still have problems bypassing the firewall. For example:


# Using googleway
google_distance(org, dest, mode = "driving", key = myKey)

# Error in value[[3L]](cond) : 
#  There was an error downloading results. Please manually check the following # URL is valid by entering it into a browswer. If valid, please file a bug 
# report citing this URL (note: your API key has been removed, so you will need # to add that back in) 

# https://maps.googleapis.com/maps/api/distancematrix/json?# 
#&origins=waco,+texas&destinations=houston,+texas&alternatives=false&units=metri# c&mode=driving&key=

# Using gmapsdistance
gmapsdistance(origin = "Washington+DC", destination = "Chicago+IL", mode = "driving", key = myKey)

#Error in function (type, msg, asError = TRUE)  : 
#  Failed to connect to maps.googleapis.com port 80: Timed out

You can see that both google_distance and gmapsdistance both fail with what appears to be a firewall error.

Can someone please help me understand how to consistently bypass the firewall, and how to use the other two packages for calculating driving distances and times?

Phil
  • 578
  • 3
  • 7
  • 17
  • have you tried using the [`curl_proxy`](https://github.com/SymbolixAU/googleway/issues/26) argument? – SymbolixAU Aug 13 '19 at 22:27
  • @SymbolixAU I did, following your example here: https://github.com/SymbolixAU/googleway/issues/26, specifically the comment from August 8, 2016. I believe I followed the example correctly, but it still did not work. Same error. – Phil Aug 14 '19 at 11:46
  • I'm afraid it's beyond me; I'm not behind a firewall so I can't test, and the limit to my knowledge is contained in that github thread. – SymbolixAU Aug 14 '19 at 22:07
  • @SymbolixAU yes I know. It is hard to create reproducible examples when dealing with a firewall. Thanks for the help – Phil Aug 15 '19 at 13:25
  • You need to configure your firewall (e.g. set IP based firewall rules) to whitelist the connections being made to Google's servers. Please open a support ticket for technical assistance: https://developers.google.com/maps/support/#contact_maps_support – evan Aug 16 '19 at 09:13

2 Answers2

0

Based on a comparison from Google Trends, we find that there were significantly more searches for ggmap than the other two libraries.

It is most likely the case that your company has already whitelisted source references for ggmap (but not the other googleway or gmapsdistance) because of its relative popularity.

Royce Yang
  • 43
  • 5
0

Set the http proxy in Renviron.site works for gmapsdistance.

Example:

http_proxy=http://proxy.dom.com/
http_proxy_user=user:passwd

https_proxy=https://proxy.dom.com/
https_proxy_user=user:passwd
Unheilig
  • 16,196
  • 193
  • 68
  • 98