google_snapToRoads: Snap To Roads

View source: R/google_roads.R

google_snapToRoadsR Documentation

Snap To Roads


Takes up to 100 GPS coordinates collected along a route and returns a similar set of data, with the points snapped to the most likely roads the vehicle was treveling along


  lat = NULL,
  lon = NULL,
  interpolate = FALSE,
  simplify = TRUE,
  curl_proxy = NULL,
  key = get_api_key("roads")



data.frame with at least two columns specifying the latitude & longitude coordinates, with a maximum of 100 pairs of coordinates.


string specifying the column of df_path containing the 'latitude' coordinates. If left NULL, a best-guess will be made.


string specifying the column of df_path containing the ' longitude' coordinates. If left NULL, a best-guess will be made.


logical indicating whether to interpolate a path to include all points forming the full road-geometry. When TRUE, additional interpolated points will also be returned, resulting in a path that smoothly follows the geometry of the road, even around corners and through tunnels. Interpolated paths will most likely contain more ponts that the original path.


logical - TRUE indicates the returned JSON will be coerced into a list. FALSE indicates the returend JSON will be returned as a string


a curl proxy object


string A valid Google Developers Places API key

API use and limits

The amount of queries you can make to Google's APIs is dependent on both the service and the API you are using.

Each API has specific quotas and limits. Check Google's API documentation for details.

View your usage at the Google Cloud Console

Each API can only accept and return one request at a time. If you write a loop to make multiple API calls you should ensure you don't go over your quota / limits during the loop.


The snapping algorithm works best for points that are not too far apart. If you observe odd snapping behaviour, try creating paths that have points closer together. To ensure the best snap-to-road quality, you should aim to provide paths on which consecutive pairs of points are within 300m of each other. This will also help in handling any isolated, long jumps between consecutive points caused by GPS signal loss or noise.

See Also



## Not run: 

key <- 'your_api_key'

df_path <- read.table(text = "lat lon
-35.27801 149.12958
-35.28032 149.12907
-35.28099 149.12929
-35.28144 149.12984
-35.28194 149.13003
-35.28282 149.12956
-35.28302 149.12881
-35.28473 149.12836", header = T)

google_snapToRoads(df_path, key = key, interpolate = TRUE, simplify = TRUE)

## End(Not run)

googleway documentation built on March 18, 2022, 7:34 p.m.