Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

'sf'-Compatible Interface to Google Maps APIs

License

NotificationsYou must be signed in to change notification settings

michaeldorman/mapsapi

Repository files navigation

CRAN_Status_BadgeCRAN_Downloads_Badge

mapsapi

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, functionsmp_get_routes andmp_get_segments can be used to process the response document intoa spatial layer. Functionmp_get_routes gives each alternative asa separate line, while functionmp_get_segments gives each segment(that is, a portion of the route associated with specific drivinginstructions) as a separate line.

  • Given adistance matrix response, functionmp_get_matrix can beused to obtain distance/duration matrices.

  • Given ageocode response, functionsmp_get_points andmp_get_bounds can 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.

Installation

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....."

Documentation

The complete documentation can be found athttps://michaeldorman.github.io/mapsapi/.

Example

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

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors6

Languages


[8]ページ先頭

©2009-2025 Movatter.jp