Skip to contents

Search for places on Google Maps based on a given query (or many queries).

Usage

google_maps_search(
  query,
  limit = 10,
  drop_duplicates = FALSE,
  coordinates = NULL,
  skip_places = 0,
  language = "en",
  region = NULL,
  async = FALSE,
  api_key = Sys.getenv("OUTSCRAPER_API_KEY")
)

Arguments

query

(chr) the query you want to search. You can use anything that you would use on a regular Google Maps site. Additionally, you can use google_id (feature_id), place_id, or CID.

limit

(int, default = 10) The parameter specifies the limit of organizations to take from one query search.

drop_duplicates

(lgl, default = FALSE) The parameter specifies whether the bot will drop the same organizations from different queries. It makes sense when you use batching and send multiple queries inside one request.

coordinates

(chr) The parameter defines the coordinates of the location where you want your query to be applied. It has to be constructed in the next sequence: paste0(latitude, ", ", longitude), e.g. "(41.3954381,2.1628662)". Often, you can find this value while visiting Google Maps.

skip_places

(int) Skip first N places, where N should be multiple to 20 (e.g. 0, 20, 40). It's commonly used in pagination.

language

(chr, default = "en") the language to use for website.

region

(chr, default = NULL) the country to use for website. It's recommended to use it for a better search experience.

async

(lgl, default = FALSE) The parameter defines the way you want to submit your task to Outscraper. It can be set to FALSE to open an HTTP connection and keep it open until you got your results, or TRUE to just submit your requests to Outscraper and retrieve them later (usually within 1-3 minutes) with the Request Results endpoint. Each response is available for 2 hours after a request has been completed.

api_key

(chr, default = Sys.getenv("OUTSCRAPER_API_KEY")) Your API key. You can get it by registering on Outscraper.

Value

a tibble with places from Google Maps on each row, based on a given search query (or many queries).

Details

Queries

The example of valid queries:

  • Real estate agency, Rome, Italy

  • The NoMad Restaurant, NY, USA

  • restaurants, Brooklyn 11203

  • 0x886916e8bc273979:0x5141fcb11460b226

  • ChIJrZhup4lZwokRUr_5sLoFlDw

  • etc.

It supports batching by sending arrays with up to 250 queries (e.g., query=text1&query=text2&query=text3). It allows multiple queries to be sent in one request and save on network latency time. You might want to check out the web application to play with locations and categories that we would suggest.

Limit

There are no more than 500 places per one query search on Google Maps. For densely populated areas you might want to split your query into subqueries in order to get all the places inside. (e.g., c("restaurants, Brooklyn 11211", "restaurants, Brooklyn 11215")).

Drop duplicates

When TRUE the bot combines results from each query inside one big array ({'data': [...]} instead of {'data': [[...], [...], [...]]}). If the amount of ignored rows are less than 5,000% of what was actually extracted, you won't be billed for ignored records. Anyway, the results of google_map_search is always a single tibble with all the places.

Async

A good practice is to send async requests and start checking the results after the estimated execution time. Check out this Python implementation as an example.

As most of the requests take some time to be executed the async = TRUE option is preferred to avoid HTTP requests timeouts.

Results

The results from searches are the same as you would see by visiting a regular Google Maps site. However, in most cases, it's important to use locations inside queries (e.g., bars, NY, USA) as the IP addresses of Outscraper's servers might be located in different countries.

Optimization

In case no places were found by your search criteria, your search request will consume the usage of one place.

This endpoint is optimized for fast responses and can be used as a real-time API. Set the limit parameter to 10 to achieve the maximum response speed.

Examples

if (FALSE) {
  # single
  google_maps_search("pizzeria, New York", limit = 1)

  # multiple
  google_maps_search(
    c("pizzeria, New York", "pizzeria, Chicago"),
    limit = 1  # each query will return 2 places max
  )
}