I am developing a site where users can find/post - well, let's say - "things". These "things" have name, description, etc.. and the most important information about them is their location. The location consists of the city (country, sometimes state) and the street.
There is no separate input for country and state, because I want it to be filled automatically, I would like to give a list for the city, where the country and the state is given (for example the user types new, then he gets New York, NY, and other guesses.
My question is, that how could I do this most efficiently? (The site can be used from all over the world)
Thanks
You should use a service such as Geobytes API. It will provide you a way to autocomplete the city name, and then get its country, region, latitude/longitude, currency, etc.
You can perform up to 50,000 requests a day, which is enough for many cases.
Does it answer your question ?
Related
I'm designing a REST API where you can search for data in different countries, but since you can search for the same thing, at the same time, in different countries (max 4), am I unsure of the best/correct way to do it.
This would work to start with to get data (I'm using cars as an example):
/api/uk,us,nl/car/123
That request could return different ids for the different countries (uk=1,us=2,nl=3), so what do I do when data is requested for those 3 countries?
For a nice structure I could get the data one at the time:
/api/uk/car/1
/api/us/car/2
/api/nl/car/3
But that is not very efficient since it hits the backend 3 times.
I could do this:
/api/car/?uk=1&us=2&nl=3
But that doesn't work very well if I want to add to that path:
/api/uk/car/1/owner
Because that would then turn into:
/api/car/owner/?uk=1&us=2&nl=3
Which doesn't look good.
Anyone got suggestions on how to structure this in a good way?
I answered a similar question before, so I will stick to that idea:
You have a set of elements -cars- and you want to filter it in some way. My advice is add any filter as a field. If the field is not present, then choose one country based on the locale of the client:
mydomain.com/api/v1/car?countries=uk,us,nl
This field should dissapear when you look for a specific car or its owner
mydomain.com/api/v1/car/1/owner
because the country is not needed (unless the car ID 1 is reused for each country)
Update:
I really did not expect the id of the car can be shared by several cars, an ID should be unique (like a primary key in a database). Then, it makes sense to keep the country parameter with the owner's search:
mydomain.com/api/v1/car/1/owner?countries=uk,us
This should return a list of people who own a car with the id 1... but for me this makes little sense as a functionality, in this search I'll only allow one country:
mydomain.com/api/v1/car/1/owner?country=uk
I have a database of city names, but the problem is that it is not sanitized. For example, if Bangalore, India is a city then I might have the following locations in my database:
Bangalore
Bangalore, India
Bangulore, India (misspelled)
Bangalore,top city, India
Bangalore, metropolitan, india
Now I would like to sanitize this data so that the only entry that remains after the sanitation is "Bangalore, India".
I could use the data that LinkedIn or Facebook has, but I don't know if this is possible or not? Another approach could be to have a master list of city names and sanitize based on that, but this seems like a costly approach. Ideally, I'm looking for a service that would return the best matched city from a correct data set, when I'm passing any city name (correct or incorrect) as input. Any pointers would be appreciated.
I am studying the development of an application that would show a user which cities in the world their friends have traveled to. To do this, I was thinking of getting a list of check-ins for each of the user's friends and mapping those check-ins to my list of cities based on each check-in latitude and longitude.
This looks like the only way to achieve this since the Facebook graph API doesn't return a city locationId that I could use to map the check-in city to my own city list.
I have absolutely no idea how to perform this mapping from a check-in lat/long to the lat/long I have stored for each city in my city table.
Could anyone point me in the right direction or toward a tutorial explaining how this can be done?
I only have a single pair of lat/long coordinates, so I suppose I would need to define for each city a range of latitudes and longitudes around the city center lat/long that would qualify a check-in for being deemed to take place in any given city, and then do a SQL query against my city table to find which city any given check-in finds itself in?
Or is there another / better way of doing this?
Thanks in advance for any tip and suggestion.
Lothaire
You can use the search API https://developers.facebook.com/docs/reference/api/#searching to search for places around a specific lat/long location.
For example, caffes in San Francisco: https://graph.facebook.com/search?q=coffee&type=place¢er=37.76,-122.427&distance=1000
Similarly, you could search for places around your coordinates and look at places type to filter out cities. You would do that by calling https://graph.facebook.com/PLACE_ID and looking at the details. For example, in the search example above, Philz Coffee (first result) - https://graph.facebook.com/151116474914629 - gives you "category": "Local business".
It's not ideal if you're aiming for cities, as check-ins are focused around places people go in the cities (you'd actually have more results of your friends checking into places probably, than them checking in to cities).
I'm trying to figure out how i can find data (from JSON) near to the users location on iPhone.
My input consists out of 2 parts, so in order to get to the city and address, I have to get an ID from the province where the user is located.
Province (with ID to go to all Json data of the province)
Data
(Every piece of data has a name, city, address, ...)
Is it possible to find the province where the user is located. Then pass its ID to search the list of data for near to the user located events by reversing all the addresses and cities into coordinates,...?
I'm pretty new to location based programming! Any help is appreciated!
Thank you very much!
The first thing you'll want to do is add CoreLocation to your app. This tutorial shows you how to do that. This will give you the latitude and longitude of your current location.
The next thing you'll want to do is reverse geocode your coordinates. One common API for this is the Google Geocoding API. That will give you your province name.
I have a form where I ask the user to input their mailing address. Would there be any issues with asking only street address and zipcode and omitting city and state?
User zipcode in conjunction with zipcode database would result in having full address of the user. Would that be reliable considering that zipcode database is accurate?
Marcin,
There is not a one to one relationship between city and zipcode. A city can have multiple zipcodes. A zipcode can cross city lines.
Brian
I wouldn't do that.
A ZIP code can contain two different towns, each with a "#123 Main Street" address.
A ZIP code may cross state lines, which means you don't have enough information for shipping/tax details.
You'll have a very hard time dealing with any customers who live outside of the USA.