API to type city name and get a list of possible c

2019-01-17 20:06发布

I need to know on which city my users are.

I cannot use a regular text input since there are similar named cities and users can call the same city by different names,.

I want to let users type their city and display a list of similar results, I could do it with a world cities database, jquery and sql but I'm really not dying to do it from a scratch.

Is there any api (e.g: google) that has an unique ID for each city in the world and let's you search them? Could you post a link to a similar implementation?

1条回答
啃猪蹄的小仙女
2楼-- · 2019-01-17 20:54

There is the Google Places Autocomplete API, https://developers.google.com/places/documentation/autocomplete

and a library for Maps Version 3 at https://developers.google.com/maps/documentation/javascript/places#places_autocomplete

but I don't know how well it will cope with different names for the same city — although, having tried it, it does present Munich, Germany for munchen — see how well your use case performs.

查看更多
登录 后发表回答