mapbox-gl-geocoder icon indicating copy to clipboard operation
mapbox-gl-geocoder copied to clipboard

consider unifying country / countries option with rest api and sdk-js

Open antony opened this issue 5 years ago • 3 comments

It looks like the official API documentation specifies "country" as an option to restrict search countries, but this library uses "countries". It's a bit confusing, and reading source code isn't an ideal way to find this out.

Is there a reason it differs, or does it make sense to unify the component configuration with the mapbox API?

antony avatar May 07 '20 11:05 antony

It's worse than that even the way you specify countries varies between here and mapbox-sdk-js

mapbox-gl-geocoder

options.countries string? a comma separated list of country codes to limit results to specified country or countries.

mapbox-sdk-js

config.countries Array? Limits results to the specified countries. Each item in the array should be an ISO 3166 alpha 2 country code.

I can't remember but think we just model this option name after the option name in mapbox-sdk-js, and since you can specify more than one country I think countries is best.

I agree that it's confusing that this doesn't match the REST API but my random guess is that originally it only supported a single country and just always left as country.

You shouldn't need to read source code to find this out though, it's all in the API documentation. If anything I think the REST API should change to countries.

andrewharvey avatar May 07 '20 13:05 andrewharvey

Ah that's interesting, and of course, understandable.

Is a good approach to maybe support both, and then deprecate over time?

antony avatar May 08 '20 13:05 antony

IMHO:

  • support 'country' as a synonym for 'countries'
  • allow the value to be provided as either comma-separated string, or array of strings.

I don't think there's much need for the control to be picky.

stevage avatar Nov 27 '20 04:11 stevage