0

Is there a limit of origin/destination pairs for googleway.distance? I tested on a few locations and got it worked:

google_distance(origins = c(38.90826, -78.20459), destinations = c(38.899799, -77.02137), 
            mode = c("driving", "walking", "bicycling", "transit"), 
            key = api_key)

But once I switched to using 2 data frames for origins and destinations (114 elements each), I got this error:

Error: lexical error: invalid char in json text.
                                   https://maps.googleapis.com/map
                 (right here) ------^

However, the code worked well for 2 data frames of 10 elements each. How many pairs am I allowed to query? I have about 300 origin/destination pairs in total, how can I get this done quickly and conveniently?

GGT
  • 43
  • 6
  • 2
    The [Google Docs](https://developers.google.com/maps/documentation/distance-matrix/usage-limits) are the ultimate source. e.g., "Maximum of 25 origins or 25 destinations per request." – SymbolixAU Feb 22 '18 at 02:27
  • And, there is a maximum length of a URL (something like 800 chars), so too many parameters will make the URL too long. – SymbolixAU Feb 22 '18 at 02:38
  • Thanks for the info @SymbolixAU! Kinda dumb question but how can I convert the output to a data frame? I tried jsonlite but this doesn't seems like a JSON output (because I choose `simplify = TRUE`?)? – GGT Feb 22 '18 at 02:45
  • It depends what information you want from the output. Using `simplify = T` will give you a `list`, so you can use standard list operations to get the information. For example, The times/distances are in `res$rows$elements` , or for convenience `distance_elements(res)` (from v2.4.0) – SymbolixAU Feb 22 '18 at 02:49
  • I tried `res1 <- distance_elements(res)`, then `ldply (res1, data.frame)' and 'do.call(rbind.data.frame, res1)` and got this error: `duplicate 'row.names' are not allowed`. – GGT Feb 22 '18 at 03:04
  • Also, I'm confusing about the output: why does it include 10 lists with 10 elements in each list? If I choose `c("driving", "walking", "bicycling", "transit")`, is the output calculated for driving by default? – GGT Feb 22 '18 at 04:27
  • I think you either need to change/update your question, or ask a new one, to ask about how to deal with the output from the `google_distance()` function, and then provide actual data to replicate the issue you're having. As it stands, this question is about the API limits, not about how to handle the response. – SymbolixAU Feb 22 '18 at 04:30
  • Right, I've posted another question. Thanks for your help! – GGT Feb 22 '18 at 14:19

0 Answers0