MyNixOS website logo
Description

Interface to the 'Azure Maps' API.

Provides a wrapper for the Microsoft 'Azure Maps' REST APIs <https://learn.microsoft.com/en-us/rest/api/maps/route?view=rest-maps-2025-01-01>, enabling users to access mapping and geospatial services directly from R. This package simplifies authenticating, building, and sending requests for services like route directions. It handles conversions between R objects (such as 'sf' objects) and the GeoJSON+JSON format required by the API, making it easier to integrate 'Azure Maps' into R-based data analysis workflows.

azuremapsr

Lifecycle:stable License: GPLv3

The goal of azuremapsr is to provide an R interface to the Microsoft Azure Maps REST APIs. This package simplifies the process of authenticating, building requests, and parsing responses for various geospatial services, starting with route directions.

Installation

You can install the latest stable version of azuremapsr from CRAN with:

install.packages("azuremapsr")   

You can also install the development version of azuremapsr from GitHub with:

# install.packages("pak")
pak::pak("juanfonsecaLS1/azuremapsr")

Authentication

Before using the package, you need a subscription key from the Azure Maps service. You can find instructions on how to obtain one here.

Once you have your key, you can set it for your R session using the set_azuremaps_token() function:

library(azuremapsr)
set_azuremaps_token("YOUR_API_KEY_HERE")

For a more permanent solution, you can store the key as an environment variable named azure_maps in your .Renviron file. You can open this file for editing by running usethis::edit_r_environ() and adding the line azure_maps='YOUR_API_KEY_HERE'.

Example

This example shows how to get the fastest driving route between two points including a waypoint.

library(azuremapsr)
library(sf)

# This example will not run unless an API key is set.
# Replace "YOUR_API_KEY_HERE" with your actual key.
# set_azuremaps_token("YOUR_API_KEY_HERE")

# Define origin, destination, and waypoint
origin <- c(-122.3321, 47.6062)  # Seattle
destination <- c(-122.0369, 47.6609) # Redmond
waypoints <- c(-122.20687, 47.612002) # Bellevue

# Define route parameters
params <- list(
  optimizeRoute = "fastestWithTraffic",
  routeOutputOptions = "routePath",
  travelMode = "driving"
)

# Get the route (requires a valid API key to be set!!!)

sample_response <-   req_route_directions(origin, destination, waypoints, params)

Routes can be extracted from the response with the get_routes function

sf_routes <- get_routes(sample_response)

plot(sf_routes$geometry,col = c("blue","red"))

These are some of the attributes returned by the service:

sf_routes |> names()
[1] "trafficCongestion"        "distanceInMeters"        
[3] "durationInSeconds"        "arrivalAt"               
[5] "departureAt"              "durationTrafficInSeconds"
[7] "type"                     "legs"                    
[9] "geometry"
Metadata

Version

0.0.2

License

Unknown

Platforms (76)

    Darwin
    FreeBSD
    Genode
    GHCJS
    Linux
    MMIXware
    NetBSD
    none
    OpenBSD
    Redox
    Solaris
    WASI
    Windows
Show all
  • aarch64-darwin
  • aarch64-freebsd
  • aarch64-genode
  • aarch64-linux
  • aarch64-netbsd
  • aarch64-none
  • aarch64-windows
  • aarch64_be-none
  • arm-none
  • armv5tel-linux
  • armv6l-linux
  • armv6l-netbsd
  • armv6l-none
  • armv7a-linux
  • armv7a-netbsd
  • armv7l-linux
  • armv7l-netbsd
  • avr-none
  • i686-cygwin
  • i686-freebsd
  • i686-genode
  • i686-linux
  • i686-netbsd
  • i686-none
  • i686-openbsd
  • i686-windows
  • javascript-ghcjs
  • loongarch64-linux
  • m68k-linux
  • m68k-netbsd
  • m68k-none
  • microblaze-linux
  • microblaze-none
  • microblazeel-linux
  • microblazeel-none
  • mips-linux
  • mips-none
  • mips64-linux
  • mips64-none
  • mips64el-linux
  • mipsel-linux
  • mipsel-netbsd
  • mmix-mmixware
  • msp430-none
  • or1k-none
  • powerpc-linux
  • powerpc-netbsd
  • powerpc-none
  • powerpc64-linux
  • powerpc64le-linux
  • powerpcle-none
  • riscv32-linux
  • riscv32-netbsd
  • riscv32-none
  • riscv64-linux
  • riscv64-netbsd
  • riscv64-none
  • rx-none
  • s390-linux
  • s390-none
  • s390x-linux
  • s390x-none
  • vc4-none
  • wasm32-wasi
  • wasm64-wasi
  • x86_64-cygwin
  • x86_64-darwin
  • x86_64-freebsd
  • x86_64-genode
  • x86_64-linux
  • x86_64-netbsd
  • x86_64-none
  • x86_64-openbsd
  • x86_64-redox
  • x86_64-solaris
  • x86_64-windows