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?
2) Make another web-service call to https://maps.googleapis.com/maps/api/place/details/json?key=API_KEY&placeid=place_id_retrieved_in_step_1. This will return a JSON which contains address_components . Looping through the types to find locality and postal_code can give you the city name and postal code.
The API is available for developers that have a free Google Maps API key. Usage of the API is not strictly free, but they do offer $200 of free monthly usage for most users. The pricing scales to fit your particular needs and you are only charged for your API usage.
Ensure that the API key(s) used for all Place Autocomplete and Place Details requests within a session belong to the same Cloud Console project. Be sure to pass a unique session token for each new session. Using the same token for more than one session will result in each request being billed individually.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With