Getting driving distance between two points (lat, lon) using R and Google Map API

前端 未结 5 592
失恋的感觉
失恋的感觉 2021-01-30 18:29

I am trying to get the driving distance between two points with lat/lon given. I can manually put them into google map and get the driving distance but I want to do all this pr

5条回答
  •  悲&欢浪女
    2021-01-30 19:10

    I needed to calculate driving distances for a bunch of addresses, so I wrote a short function for it and put it in a likewise small packet. You can find it in my GitHub repo: https://github.com/JanMultmeier/GeoData/blob/master/GeoDataPackage/R/GetDist.R

    This should get it to run:

    require(devtools)
    install_github("JanMultmeier/GeoData/GeoDataPackage")
    library(GeoData)
    getDist(from="1 Infinity Loop, Cupertino, CA 95014", to="1600 Amphitheatre Pkwy, Mountain View, CA 94043",modus="driving",get="distance")
    

    It should return 14.8 km.

    Barryhunter has already hinted at the usage restriction by Google, which ties the use of this API to displaying the results on a Google map.

    Hope that still helps some people who stumble across this post (like me)...

提交回复
热议问题