#Assign fields
data_frame <- data.frame()
api_key <- "Your_API_ID"
location <- "40.7128,-74.0060"
radius <- 1000
type <- "restaurant"
url <- paste0(
"https://maps.googleapis.com/maps/api/place/nearbysearch/json?",
"location=", location,
"&radius=", radius,
"&type=", type,
"&key=", api_key
)
response <- GET(url)
data <- fromJSON(content(response, "text"))
data_frame <- as.data.frame(data$results)Assignment 6 Learninng a New API
Introduction
I was tasked with learning a new API we have not covered in class and give an outline of how we plan to use it. In addition, I will be explaining why somebody would be interested in using this API.
New API
I Chose to learn about the Google maps Places API. This API allows users to collect information like location using a text search.
Steps for Places API
- You must create an API on Google Cloud API and Services
- Create an API key to use to authenticate
- Input your API key into code as API
- Input fields
Example API Call
In this API Call, we are using the location of New York, NY. The fields of this search are the location, which is the coordinates of this specific location, the radius of the area we are searching, which is 1000, and the type as restaurant.
Output
There are 20 outputs per page for this API, so if you desire more, then you can add a field to add more pages. We have Business Status, Geometric location latitude and longitude, Open hours, rating, Price level, and strings for “types” of restaurant. With this, we can make several decisions based on the data given.