Last chance! 50% off unlimited learning
Sale ends in
The Google Maps Elevation API provides elevation data for all locations on the surface of the earth, including depth locations on the ocean floor (which return negative values).
google_elevation(
df_locations = NULL,
polyline = NULL,
location_type = c("individual", "path"),
samples = NULL,
key = get_api_key("elevation"),
simplify = TRUE,
curl_proxy = NULL
)
Either list or JSON string of the elevation data
data.frame
of with two columns called 'lat' and 'lon'
(or 'latitude' / 'longitude') used as the locations
string
encoded polyline
string
Specifies the results to be returned as individual
locations or as a path. One of 'individual' or 'path'. If 'path', the data.frame
df_locations
must contain at least two rows. The order of the path is
determined by the order of the rows.
integer
Required if location_type == "path"
.
Specifies the number of sample points along a path for which to return elevation data.
The samples parameter divides the given path into an ordered set of equidistant
points along the path.
string
A valid Google Developers Elevation API key
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
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 https://console.cloud.google.com/
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.
Locations can be specified as either a data.frame containing both a lat/latitude and lon/longitude column, or a single encoded polyline
if (FALSE) {
set_key("YOUR_GOOGLE_API_KEY")
## elevation data for the MCG in Melbourne
df <- data.frame(lat = -37.81659,
lon = 144.9841)
google_elevation(df_locations = df,
simplify = TRUE)
## elevation data from the MCG to the beach at Elwood (due south)
df <- data.frame(lat = c(-37.81659, -37.88950),
lon = c(144.9841, 144.9841))
df <- google_elevation(df_locations = df,
location_type = "path",
samples = 20,
simplify = TRUE)
## plot results
library(ggplot2)
df_plot <- data.frame(elevation = df$results$elevation,
location = as.integer(rownames(df$results)))
ggplot(data = df_plot, aes(x = location, y = elevation)) +
geom_line()
}
Run the code above in your browser using DataLab