gmapsdistance, starttag: invalid element name

Hi, all
I am running the following code to calculate the travel time (walking) between the neighborhoods in a region of amman. I use the package gmapsdistance.

When I run the code, I got an error like "Error: 1: StartTag: invalid element name".
Then I check the results table to observe at which row the code stopped writing.
When I remove that row, the code runs until the next row that causes error.

I cross checked google maps to see if the lat+long entry (of either origin or destination region) has a problem on maps. But it doesn't for the samples I checked.

I also checked the lat+long for the non-problematic rows, there doesn't seem to be difference.

Any idea about why I am getting this error? Thanks

Btw, sample _origin_latlon.txt and sample _dest_latlon.txt files have one column with 'lat+long' entries. (like 32.00885+36.0337)


rm(list=ls( = TRUE))
if ([["user"]]=='esmao')
  setwd("the path to the directory")	

# Read in the data
x1 <- scan("sample_origin_latlon.txt", what="", sep="\n")
x2 <- scan("sample_dest_latlon.txt", what="", sep="\n")

location <- c(1:1000)

# Walking 
results_walking <- matrix(NA, nrow = 1000, ncol = 5)
colnames(results_walking) <- c("Orig","Des","Time","Distance","Status")
for (h in location){
  results = gmapsdistance(x1[h], x2[h], mode = "walking", combinations = "pairwise",
                          key="Api copied here",shape = "wide", dep_date = "2021-08-18", dep_time = "9:30:00")
  results_walking[h,1] <- x1[h]
  results_walking[h,2] <- x2[h]
  results_walking[h,3] <- results$Time
  results_walking[h,4] <- results$Distance
  results_walking[h,5] <- results$Status
write.csv(results_walking,"google_maps/walking.csv", row.names = FALSE)

Are you dead set on using gmapsdistance? I have very good experience with HERE API / accessible from via {hereR} package. I have on the other hand bad experience with (frequently changing and sometimes unclear) Google APIs. Once burned, twice shy...

The HERE (the artist formerly known as Nokia Maps) API supports pedestrian routing, and I have found it to be both convenient and reliable. Like Google it requires registration, and provides a generous free tier.

BTW I wrote a blog post a while back comparing several routing options available to R users Road Routing in R · Jindra Lacko

1 Like

Thanks for the suggestion I took a look at HERE. It might be a good alternative,
but I would like to use gmapsdistance for the consistency in the project I'm working. So, the priority would be to resolve the issue with gmapsdistance. If unlikely, then HERE.


This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.