Skip to content

Are missing values parsed as query parameters? #59

@etiennebacher

Description

@etiennebacher

Hello, thanks for the great package and documentation!

When doing batch geocoding, I noticed that some results didn't make sense (for instance returning locations in Ireland when my list of addresses are clearly located in Germany and I passed the country parameter to specify that). It turns out that missing values can completely modify the query.

Take for instance this example:

library(mapboxapi)
#> Usage of the Mapbox APIs is governed by the Mapbox Terms of Service.
#> Please visit https://www.mapbox.com/legal/tos/ for more information.

mb_geocode(
  structured_input = list(
    address_line1 = NA,
    place = NA,
    postcode = NA,
    country = NA
  ),
  output = "sf"
)
#> Simple feature collection with 1 feature and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 24.88528 ymin: -17.63129 xmax: 24.88528 ymax: -17.63129
#> Geodetic CRS:  WGS 84
#>                     id            mapbox_id feature_type
#> 1 dXJuOm1ieHBsYzpFb2lp dXJuOm1ieHBsYzpFb2lp        place
#>                 full_address                   geometry longitude  latitude
#> 1 Nangwena, Zambezi, Namibia POINT (24.88528 -17.63129)  24.88528 -17.63129

All the components are missing, but it still returns a location in Namibia? I suspect this is because NA is parsed as "NA", which is the ISO-2 code for Namibia, but that's very unexpected to me. Shouldn't this call return NA instead? More generally, shouldn't all missing fields be dropped when building the query to be passed to Mapbox?


Edit: this is also an issue when using the search_text parameter:

library(mapboxapi)
#> Usage of the Mapbox APIs is governed by the Mapbox Terms of Service.
#> Please visit https://www.mapbox.com/legal/tos/ for more information.

mb_geocode(search_text = NA, output = "sf")
#> Simple feature collection with 1 feature and 6 fields
#> Geometry type: POINT
#> Dimension:     XY
#> Bounding box:  xmin: 136.9034 ymin: 35.1687 xmax: 136.9034 ymax: 35.1687
#> Geodetic CRS:  WGS 84
#>                     id            mapbox_id feature_type           full_address
#> 1 dXJuOm1ieHBsYzpKV2gw dXJuOm1ieHBsYzpKV2gw        place 名古屋市, Aichi, Japan
#>                   geometry longitude latitude
#> 1 POINT (136.9034 35.1687)  136.9034  35.1687

But why is a location in Japan returned? I have no clue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions