R gmapsdistance XML Error

639 views Asked by At

I am using gmapsdistance in a for loop to get the drive time for a list of addresses. Below is the R code:

for( i in 1: nrow(data_subset)){

    if( i!= nrow(data_subset)){

      print(i)  

      drive_time <- gmapsdistance(origin=Data_subset$Address[i], destination =Data_subset$Address[i+1], mode='driving', departure = 'now',traffic_model = 'pessimistic')$Time

      print(drive_time)

      tot_drive_time <- drive_time  + tot_drive_time

    }
}

The data_subset is a dataframe that has the list of addresses. I am trying to find the total drive time from A to B then B to C then C to D, goes on till the end of data frame.

But I am getting an XML at some random points. Each time I run I get an error at different data points.

Error in UseMethod("xmlChildren") : no applicable method for 'xmlChildren' applied to an object of class "NULL"

How do I resolve this? Any other better solution? Please share

1

There are 1 answers

1
Shriram Srinivasan On BEST ANSWER

AFAIK, It's an API key issue. Google maps API usage policy (https://developers.google.com/maps/documentation/javascript/distancematrix) limits the number of queries for free API keys. You need to get a paid license or break the data frame into smaller sub data frames and run loops for them separately at different points in time.