google_elevation: Google elevation

View source: R/google_elevation.R

google_elevationR Documentation

Google elevation


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).


  df_locations = NULL,
  polyline = NULL,
  location_type = c("individual", "path"),
  samples = NULL,
  key = get_api_key("elevation"),
  simplify = TRUE,
  curl_proxy = NULL



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


Locations can be specified as either a data.frame containing both a lat/latitude and lon/longitude column, or a single encoded polyline


Either list or JSON string of the elevation data

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.


## Not run: 

## 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
df_plot <- data.frame(elevation = df$results$elevation,
                       location = as.integer(rownames(df$results)))

ggplot(data = df_plot, aes(x = location, y = elevation)) +

## End(Not run)

googleway documentation built on Aug. 22, 2023, 9:13 a.m.