SymbolixAU / googleway

R Package for accessing and plotting Google Maps
http://symbolixau.github.io/googleway/
Other
234 stars 46 forks source link

google_places: radius argument not respected? #244

Closed werkstattcodes closed 2 years ago

werkstattcodes commented 2 years ago

First, many thanks for this amazing package.

I am using google_placesto check for the presence of a specific company, e.g. a bank, within a specific radius (100 m) around a lat/long combination. Surprisingly, however, the result includes a company which is further away than the radius. Below an example where the returned object is more than 300 m away, although the radius is set to 100 m. Is this a bug, or am I missing something how to limit the google_placesresults to the value stipulated in the radius. Many thanks.

library(googleway)
library(tidyverse)
library(geosphere)

loc_lat <- 44.1996344
loc_lng <- 17.9069263

df_places <- google_places(
  name =  "Asa Bank",
  location = c(loc_lat, loc_lng),
  radius = 100,
  place_type = "bank",
  key = Sys.getenv("GooglePlaces_key")) 

df_res <- df_places$results
df_res$lat <- df_res$geometry$location$lat
df_res$lat
#> [1] 44.20185
df_res$lng <- df_res$geometry$location$lng
df_res$lng
#> [1] 17.90444

distHaversine(cbind(loc_lng, loc_lat),
              cbind(df_res$lng, df_res$lat))
#> [1] 316.8174

Created on 2022-04-05 by the reprex package (v2.0.1)

dcooley commented 2 years ago

I believe Google will still display results outside of your desired radius:

https://developers.google.com/maps/documentation/places/web-service/search-text#radius

Defines the distance (in meters) within which to return place results. You may bias results to a specified circle by passing a location and a radius parameter. Doing so instructs the Places service to prefer showing results within that circle; results outside of the defined area may still be displayed.