
This is a work file - see the slides for the final code.

```{r}
library(tidyverse)
library(mdsr)
library(sf)
library(tidygeocoder)
```

[tidygeocoder](https://jessecambon.github.io/tidygeocoder/)

```{r}
addresses <- tibble(address = c(
  "3201 Burton Street SE, Grand Rapids, MI, 49546", # Calvin
  "303 Monroe Ave NW, Grand Rapids, MI, 49503" # DeVos Hall
  )) %>% 
  tidygeocoder::geocode(address, method = "osm")%>%
  st_as_sf(coords = c("long", "lat")) %>%
  st_set_crs(4326)  
addresses
```


```{r}
addresses %>% st_as_sf(coords = c("long", "lat"), crs = 4326) %>% 
  ggplot() +
    annotation_map_tile() +
    geom_sf()
```

```{r}
addresses %>%
  st_distance() %>%
  units::set_units("miles")
```

```{r}
library(openrouteservice)
ors_api_key("5b3ce3597851110001cf6248a0ea007927bd461284a3c332fdea13fd")

calvin_devos <- addresses %>%
  st_coordinates() %>%
  as_tibble()

route_driving <- calvin_devos %>%
  ors_directions(profile = "driving-car", output = "sf")

route_driving %>%
  st_length() %>%
  units::set_units("miles")
```

```{r}
route_cycling <- calvin_devos %>%
  ors_directions(profile = "cycling-regular", output = "sf")

route_cycling %>%
  st_length() %>%
  units::set_units("miles")
```

```{r}
library(leaflet)
leaflet() %>%
  addTiles() %>%
  addPolylines(data = route_driving, 
               weight = 7
               ) %>%
  addPolylines(data = route_cycling, 
               color = "green", 
               weight = 7
               )
```


