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)
library(gmapsdistance)
library(data.table)
library("readr")
rm(list=ls(all.name = TRUE))
if (Sys.info()[["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)