Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
815 views
in Technique[技术] by (71.8m points)

autocomplete - Enforce MapBox Geocoding API to return only results with a zipcode

I'm working with MapBox Geocoding API to have suggestions of addresses in the location search feature of my website.

The following is a sample call:

https://api.mapbox.com/geocoding/v5/mapbox.places/Zur.json?country=ch&limit=5&proximity=8.765.432&language=en-GB&access_token=***

My goal is to enforce the api to return only results that include a zipcode.

For example if I input "Zur" (limiting the search to Swiss) I get the following:

 - Zürich, Zürich, Switzerland
 - Zürich, Switzerland
 - Zürich Airport, Flughafenstrasse, Kloten, Zürich 8302, Switzerland
 - Zurich, Buchs, Zürich 8107, Switzerland

The expected results should be without the first two lines, as they don't have a zipcode.

I tried implementing myself the removal of results without the zipcode on client side (just after I got an answer from the api), but it is a suboptimal solution (for example it doesn't ensure to have enough results).

I was not able to find such feature in MapBox. Is there a better solution out of there?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Just add ?types=address

See all list of types: https://docs.mapbox.com/api/search/geocoding/#data-types


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...