jessecambon/tidygeocoder

mapbox error when reverse geocoding with limit > 1

jessecambon opened this issue · 2 comments

library(tidygeocoder)
sample_lats <- c(38.89770, 41.87886)
sample_longs <- c(-77.03655, -87.63592)

limit_null <- reverse_geo(lat = sample_lats, long = sample_longs, mode = 'single',
                         method = 'mapbox', full_results = TRUE, limit = 35, return_coords = FALSE)

Results in:

Error: limit must be combined with a single type parameter when reverse geocoding
Error: limit must be combined with a single type parameter when reverse geocoding
Warning messages:
1: In query_api(api_url, api_query_parameters, method = method) :
Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).
2: In query_api(api_url, api_query_parameters, method = method) :
Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).

@dieghernan have you seen this before when testing mapbox?

Indeed, it was tested:

livetest_params <-
tidygeocoder::reverse_geo(
lat = c(48.858296, 40.4530541),
long = c(2.294479, -3.6883445),
verbose = TRUE,
full_results = TRUE,
limit = 3,
method = "mapbox",
custom_query = list(
language = "pl",
types = "address"
),
)

What happens here is that if you want to use reverse geocoding + limit > 1 with Mapbox, you need to supply also a type value on the custom query. From the docs https://docs.mapbox.com/api/search/geocoding/#geocoding-api-errors:

limit must be combined with a single type parameter when reverse geocoding - If you make a reverse geocoding request with the limit parameter, you must also use the type parameter.

Type parameter is described here.

See a full reprex with your example and the same call with types:

sample_lats <- c(38.89770, 41.87886)
sample_longs <- c(-77.03655, -87.63592)

# Fail
tidygeocoder::reverse_geo(
  lat = sample_lats,
  long = sample_longs,
  mode = 'single',
  method = 'mapbox',
  full_results = TRUE,
  limit = 35,
  return_coords = FALSE
)
#> Warning in query_api(api_url, api_query_parameters, method = method):
#> Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).
#> Error: limit must be combined with a single type parameter when reverse geocoding
#> Warning in query_api(api_url, api_query_parameters, method = method):
#> Unprocessable Entity (WebDAV; RFC 4918) (HTTP 422).
#> Error: limit must be combined with a single type parameter when reverse geocoding
#> # A tibble: 2 x 1
#>   address
#>   <chr>  
#> 1 <NA>   
#> 2 <NA>

# Not Fail
tidygeocoder::reverse_geo(
  lat = sample_lats,
  long = sample_longs,
  mode = 'single',
  method = 'mapbox',
  full_results = TRUE,
  limit = 35,
  return_coords = FALSE,
  # Note this line
  custom_query = list(types = "poi"),
)
#> # A tibble: 10 x 15
#>    address          id      type  place_type relevance text      center context 
#>    <chr>            <chr>   <chr> <list>         <int> <chr>     <list> <list>  
#>  1 The White House~ poi.59~ Feat~ <chr [1]>          1 The Whit~ <dbl ~ <df[,4]~
#>  2 White House Nav~ poi.12~ Feat~ <chr [1]>          1 White Ho~ <dbl ~ <df[,4]~
#>  3 Red Room, 1600 ~ poi.34~ Feat~ <chr [1]>          1 Red Room  <dbl ~ <df[,4]~
#>  4 James S. Brady ~ poi.20~ Feat~ <chr [1]>          1 James S.~ <dbl ~ <df[,4]~
#>  5 Blue Room, 1600~ poi.85~ Feat~ <chr [1]>          1 Blue Room <dbl ~ <df[,4]~
#>  6 Brandmuscle, 23~ poi.12~ Feat~ <chr [1]>          1 Brandmus~ <dbl ~ <df[,4]~
#>  7 James Svigos - ~ poi.11~ Feat~ <chr [1]>          1 James Sv~ <dbl ~ <df[,4]~
#>  8 Chicago Metropo~ poi.10~ Feat~ <chr [1]>          1 Chicago ~ <dbl ~ <df[,4]~
#>  9 Bank of America~ poi.72~ Feat~ <chr [1]>          1 Bank of ~ <dbl ~ <df[,4]~
#> 10 Beehive Shoewor~ poi.13~ Feat~ <chr [1]>          1 Beehive ~ <dbl ~ <df[,4]~
#> # ... with 7 more variables: properties.wikidata <chr>,
#> #   properties.foursquare <chr>, properties.landmark <lgl>,
#> #   properties.address <chr>, properties.category <chr>, geometry.type <chr>,
#> #   geometry.coordinates <list>

Created on 2021-04-06 by the reprex package (v1.0.0)