GithubHelp home page GithubHelp logo

mapsapi's Introduction

CRAN_Status_Badge CRAN_Downloads_Badge

mapsapi

The mapsapi package provides an interface to the Google Maps APIs, currently four of them:

Functions mp_directions, mp_matrix and mp_geocode are used to access the Directions, Matrix and Geocode APIs, respectively. They return an xml_document object (package xml2) with the response contents.

  • Given a directions response, functions mp_get_routes and mp_get_segments can be used to process the response document into a spatial layer. Function mp_get_routes gives each alternative as a separate line, while function mp_get_segments gives each segment (that is, a portion of the route associated with specific driving instructions) as a separate line.

  • Given a distance matrix response, function mp_get_matrix can be used to obtain distance/duration matrices.

  • Given a geocode response, functions mp_get_points and mp_get_bounds can be used to obtain geocoded locations as a point or polygon (bounds) layer.

The fourth function mp_map is used to access the Maps Static API. It returns a stars raster RGB image, which can be used as background in maps.

Installation

The CRAN version can be installed with:

install.packages("mapsapi")

The development version can be installed using remotes:

install.packages("remotes")
remotes::install_github("michaeldorman/mapsapi")

Once installed, the package can be loaded with library:

library(mapsapi)

Note: due to new Google Maps API policy, starting from June 2018 the functions require an API key.

key = "AIz....."

Documentation

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

Example

The following code section obtains (and plots) the driving directions from 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' layer
r = mp_get_routes(doc)

# Plot
library(maps)
library(sf)
#> Linking to GEOS 3.8.0, GDAL 3.0.4, PROJ 6.3.1
map("state", fill = FALSE, col = "grey")
plot(st_geometry(r), col = c("red", "green", "blue"), add = TRUE)

mapsapi's People

Contributors

michaeldorman avatar mihirbhaskar avatar tbdv avatar tbuckl avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.