tag:blogger.com,1999:blog-1816488797213954066.post4288836849641451299..comments2023-10-17T05:43:46.740-04:00Comments on eKonometrics: Google maps and travel timesMurtaza Haiderhttp://www.blogger.com/profile/11315309304368143831noreply@blogger.comBlogger2125tag:blogger.com,1999:blog-1816488797213954066.post-71823438916608147592011-04-04T06:36:31.837-04:002011-04-04T06:36:31.837-04:00I'm just working on that kind of travel distan...I'm just working on that kind of travel distance calculations, and I use this method (rjson).<br />Here is my code with coordinates specifications (and not cities specifications) :<br />library(RCurl)#To get the result of an url<br />library(rjson)#To read json files<br /><br />#An example of coordinates<br />xlat<-57.372801<br />xlong<-2.016214<br />ylat<-57.459688<br />ylong<-2.790558<br /><br />#Writing the corresponding url<br />z<-paste("http://maps.google.com/maps/api/directions/json?origin=",xlat,",",xlong,"&destination=",ylat,",",ylong,"&sensor=false",sep="")<br /><br />#To get and read the json file<br />x<-fromJSON(getURL(url=z))<br /><br />#To catch the Google limitation on requests (it often happens)<br />if(x$status=="OVER_QUERY_LIMIT"){<br />while(x$status=="OVER_QUERY_LIMIT"){Sys.sleep(10*60) ;print("wait for 10 mins")}<br />}<br />x<-fromJSON(getURL(url=z))<br /><br /><br />#To get the total travel time<br />TRAVEL_TIME<-x[[2]][[1]][[2]][[1]][[2]]$text<br />print(TRAVEL_TIME)<br /><br />But I often get the OVER_QUERY_LIMIT message : Anybody knows How to nicely avoid this annoyance ?Anonymoushttps://www.blogger.com/profile/02602838537740592922noreply@blogger.comtag:blogger.com,1999:blog-1816488797213954066.post-38412001353637310692011-04-02T11:13:28.895-04:002011-04-02T11:13:28.895-04:00The TravelR project looks interesting. Getting tra...The TravelR project looks interesting. Getting travel distance and time from Google Maps is easy using the rjson library:<br /><br />library(rjson)<br />json_file<- "http://maps.google.com/maps/nav?output=js&q=from:%20Montreal%20to:%20Toronto"<br />json_data <- fromJSON(paste(readLines(json_file), collapse=""))<br />json_data$Directions$Duration$html<br />json_data$Directions$Routes[[1]]$Distance$metersAnonymoushttps://www.blogger.com/profile/02888857072921986860noreply@blogger.com