michaeldorman / mapsapi

'sf'-Compatible Interface to Google Maps APIs
Other
50 stars 14 forks source link

Typo error in mp_get_routes() #2

Closed MathieuMarauri closed 6 years ago

MathieuMarauri commented 6 years ago

Hello,

I am trying out your package and I am having fun using it.

I wanted to get the direction from one point to another one and I noticed that when you use mp_get_routes to get an sf object from the result of mp_direction the geometry column is called geomerty. It is far from a big deal but if you want to then plot it with ggplot2 you might get an error depending on the way you call geom_sf().

ggplot(data = direction) + geom_sf() will give an error.

Thank you for your package.

Cheers,

Mathieu

michaeldorman commented 6 years ago

Hi Mathieu,

Thanks! The typo is now corrected and geom_sf should work.

The following is a reproducible example (replacing the key with your Google Maps API key)

library(mapsapi)
library(ggplot2)

# Get routes
key = "GOOGLE API KEY"
doc = mp_directions(
  origin = c(34.81127, 31.89277),
  destination = c(34.781107, 32.085003),
  departure_time = Sys.time(),
  alternatives = TRUE,
  key = key
)
r = mp_get_routes(doc)

# Plot with 'ggplot2'
ggplot() + 
  geom_sf(
    data = r, 
    aes(colour = factor(alternative_id))
  )

Here is the resulting plot - plot

Best regards,

Michael

MathieuMarauri commented 6 years ago

Great, thank you 👍