I'm accepting a user input which is supposed to be a geographic location. I would like to validate that what the user has entered describes a location--e.g., postal code, airport code, street address, city name, etc.
The obvious answer is to use the Google Geocode API to do a request for the user's input and see if I get any results.) However the geocode ToS forbids this:
...the Geocoding API may only be used in conjunction with a Google map; geocoding results without displaying them on a map is prohibited.
Does anyone know of alternatives?
Yahoo also has a geolocation API which has a less-restrictive TOS. By querying for a location, if you receive a non-null result set then you know its a valid place.
# A query for New York...
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='New+York'&format=json
# Results in a response
{"query":{"count":10,"created":"2013-01-11T18:40:32Z","lang":"en-US","results":{"place":[... places ... ] }}}
whereas
# A query for junk
http://query.yahooapis.com/v1/public/yql?q=select%20%2a%20from%20geo.places%20where%20text='kqpo234xk'&format=json
# Results in null
{"query":{"count":0,"created":"2013-01-11T18:39:21Z","lang":"en-US","results":null}}
Related
My company gets the addresses the loading hubs for our freights every week. We need to geocode them into coordinates. But often the addresses either are incomplete or contain minor grammar mistakes, so it's impossible to input them for geocoding.
My question : when dealing with a list of wrong or incomplete addresses when geocoding, is there any general solution to solve the issue ?
If there are useful articles or resources about this topic, please let me know.
Thank you.
Geocoding / Autocomplete
According to the Geocoding Addresses Best Practices documentation:
"Geocoding is the process of converting addresses (like a street address) into geographic coordinates (latitude and longitude), which you can use to place markers on a map, or position the map."
"In general, use the Geocoding API when geocoding complete addresses (for example, “48 Pirrama Rd, Pyrmont, NSW, Australia”). Use the Places API Place Autocomplete service when geocoding ambiguous (incomplete) addresses."
The Place Autocomplete service returns place predictions according to your inputs. This would solve your problem of having wrongly spelled addresses.
How to get the coordinates after using Place Autocomplete?
example request for Place Autocomplete would look like this:
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Paris&types=geocode&key=YOUR_API_KEY
The Place Autocomplete is able to return the address description together with its place_id. In this sample request, you are able to get "description": "Paris, France" with a "place_id": "ChIJD7fiBh9u5kcRYJSMaMOCCwQ".
Then you can use the Place ID of the predicted location to obtain the coordinates of that place by using Place Details request
You can request it like this:
https://maps.googleapis.com/maps/api/place/details/json?fields=geometry&place_id=ChIJD7fiBh9u5kcRYJSMaMOCCwQ&key=YOUR_API_KEY
We used here the fields=geometry to only return the coordinates of the location and as previously mentioned the Place ID we used is the one we had from the Autocomplete query.
The returned data will be the expected result according to your question. But feel free to comment if you need anything.
To read more about the fields parameter, refer to the Place Details documentation.
I hope this helps!
I'm using OmniAuth and the Koala gem to add Facebook Connect to my app and i'm trying to get the user's country.
So far I have:
graph = Koala::Facebook::API.new(user.oauth_token)
profile = graph.get_object("me")
profile["location"] gives me the id and name of the city.
I've tried: graph.get_object(city_id) which returns the city object, but I can't find any mention of the city's country in it.
I can also get the country name from the location string: "Kfar Saba, Israel" but that seems like a hack... Any official way to get what i'm looking for? Thanks!
There's the issue that the location data is not always complete for Place pages. I think you'll need to implement the location string parsing as a fallback if the location.country field of the Place page is empty. Be aware that the location string may also contain the location.state, which means that you'll have to use the last token after the split by comma.
Graph API returns no country for the named city:
https://developers.facebook.com/tools/explorer?method=GET&path=114269838585202&version=v2.0
See https://developers.facebook.com/docs/graph-api/reference/v2.0/page#readfields for the Page object structure.
I want to use the Yahoo Placefinder API for user registration for city input (auto suggest). Based on the documentation I can to the following GET request:
http://where.yahooapis.com/geocode?city=falenty&country=poland&appid=yourappid
If you put this in browser, it gives you some XML:
...
<line1/>
<line2>05-090 Falenty</line2>
<line3/>
<line4>Poland</line4>
<house/>
<street/>
<xstreet/>
<unittype/>
<unit/>
<postal>05-090</postal>
<neighborhood>Falenty</neighborhood>
<city>Raszyn</city>
<county>Pruszkow County</county>
...
But I don't want to search by neighborhood if I was searching by city. If there is no city by this name, I don't want to get any results.
Does anybody have any idea if that is possible or do I need to loop through results and exclude those results where the city is not the same as what was sent in the URI? This is not an elegant solution because sometimes it gives me more than 10 results and not even 1 with the city I was searching for.
I am having a bit of trouble sifting through the twitter API. I am trying to search for tweets near a certain location and then see their exact (or approximate) geo coordinates. I understand the geo field is deprecated and now we are supposed to use the "place" field. Unfortunately when I use the following url: http://search.twitter.com/search.json?q=&geocode=30.1829,-97.832,10mi I get a bunch of responses with a location that matches the city of the geo coordinates, but geo: is null and there is no place field. Am I stuck with only having an accuracy up to city coordinates, or am I using the wrong search call?
Thanks in advance!
Remember, tweeting with a geo location is an opt-in process. Twitter will supply a feed from the area for all tweeters in that area, but only those who have opted to tweet their coordinates will show up with "geo" info.
Using q=here with your url it did return 1 tweet for me with "geo" info in this form (though likely it will have moved on down the timeline by the time you try...):
"geo":{"coordinates":[-33.9769,18.5080],"type":"Point"}
Every user has a user defined location set in their profile settings. Use this when users don't use geo-encoding.
You can obtain a list of all countries / states by country and do a simple clean-up operation on the dataset.
This gave me what I needed for location data and greatly enriched my output.
I am using the google maps api to develop an iOS app. I need to find the nearest gas station on the map. When I call an http request: http://maps.googleapis.com/maps/api/geocode/json?address=%gas%20station&sensor=true, it returns one result. But it is the only one. There should be many results. No matter what keywords I submit, it only returns one result. Does anyone know how to deal with this?
I opened the URL in a browser and got this response :
{
"results" : [],
"status" : "ZERO_RESULTS"
}
According to Google Maps documentation here
"ZERO_RESULTS" indicates that the geocode was successful but returned no results. This may occur if the geocode was passed a non-existent address or a latlng in a remote location.
Gas station is a vague address. Try entering a valid address with a name of the area or city or the street. And you will get results. e.g. http://maps.googleapis.com/maps/api/geocode/json?address=250%20King%20St%20SF&sensor=true
You need to use the Places API to search for places like establishments(restaurants, gas stations,etc)
I don't know why, but when I printed the result to the console, it always was showing only one result. But in a debug mode with a breakpoint there were 5 results.
Please check it out using a debug mode.