- Notifications
You must be signed in to change notification settings - Fork14
'sf'-Compatible Interface to Google Maps APIs
License
michaeldorman/mapsapi
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
Themapsapi package provides an interface to the Google Maps APIs,currently four of them:
Functionsmp_directions,mp_matrix andmp_geocode are used toaccess the Directions, Matrix and Geocode APIs, respectively. Theyreturn anxml_document object (packagexml2) with the responsecontents.
Given adirections response, functions
mp_get_routesandmp_get_segmentscan be used to process the response document intoa spatial layer. Functionmp_get_routesgives each alternative asa separate line, while functionmp_get_segmentsgives each segment(that is, a portion of the route associated with specific drivinginstructions) as a separate line.Given adistance matrix response, function
mp_get_matrixcan beused to obtain distance/duration matrices.Given ageocode response, functions
mp_get_pointsandmp_get_boundscan be used to obtain geocoded locations as a pointor polygon (bounds) layer.
The fourth functionmp_map is used to access the Maps Static API. Itreturns astars raster RGB image, which can be used as background inmaps.
The CRAN version can be installed with:
install.packages("mapsapi")The development version can be installed usingremotes:
install.packages("remotes")remotes::install_github("michaeldorman/mapsapi")
Once installed, the package can be loaded withlibrary:
library(mapsapi)Note: due tonew Google Maps APIpolicy,starting from June 2018 the functions require an API key.
key="AIz....."
The complete documentation can be found athttps://michaeldorman.github.io/mapsapi/.
The following code section obtains (and plots) the driving directionsfrom New-York to Los Angeles.
# Get routes (XML document)doc= mp_directions(origin="New-York",destination="Los Angeles",alternatives=TRUE,key=key,quiet=TRUE)# Extract lines 'sf' layerr= mp_get_routes(doc)# Plotlibrary(maps)library(sf)#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1map("state",fill=FALSE,col="grey")plot(st_geometry(r),col= c("red","green","blue"),add=TRUE)
About
'sf'-Compatible Interface to Google Maps APIs
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Releases
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.
