Google Map API only returns one result? - ios

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.

Related

What are the solutions when geocoding a wrong or incomplete address?

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!

google places api returning null results

I am developing an app for ios and I'm am using the Google places api. When I make my request, I am getting a response, status reads "Ok", but every attribute is null. Interesting thing is that for different searches, I get a unique number of results, and the same number of unique lat, lng attributes. Just everything else(name, formatted address,etc...) all return null. I've searched but can find no reason for this. Anybody else have experience with this issue or maybe an idea to correct it? Thanks!
I figured it out, in my url I was using "radarsearch", where i should have been using "nearbysearch". Thanks!

Google Maps sdk with voice navigation direction in IOS?

I´ve been reading the documentation of the Google Maps SDK for iOS and I didn't see anything about voice navigation direction and route on the map.
Do anyone know about this?
I correct my previous answer this is possible. You use the google directions API as outlined in this link:
You send your direction request and it returns the directions either as json or xml as per your preference. Gives you coordinates of each point on the route.
You send a request to http://maps.googleapis.com/maps/api/directions/outputformat?parameters
So if you want to return the directions as json the request would be:
http://maps.googleapis.com/maps/api/directions/json?origin=ORIGIN_LOCATION&destination=DESTINATION_LOCATION&sensor=FALSE
the ORIGIN_LOCATION and DESTINATION_LOCATION can either be a latitude and longitude seperated by a comma e.g. latitude,longitude or a location search string e.g Eiffel+Tower+,+Paris+France (The search string has to be url encoded).
The sensor parameter is another compulsory parameter and asks whether the device sending the request can detect its own location.
For example for the directions from the eiffel tower to the louvre museum are given on the following link as json:
http://maps.googleapis.com/maps/api/directions/json?origin=Louver+museum+Paris&destination=Eiffel+Tower+Paris+France&sensor=false
And to return it as XML:
http://maps.googleapis.com/maps/api/directions/xml?origin=Louver+museum+Paris&destination=Eiffel+Tower+Paris+France&sensor=false

twitter search api no place returned

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.

how to get latitude and longitude for particular landmark?

how to get latitude and longitude for particular landmark/business, i would like to get lat/long for specific address how to i do that? shall i use gps device to get the lat/long?
Very recently, two or three weeks ago, Google released a new API that lets you do just what you want.
This is how it works:
http://maps.google.com/maps/api/geocode/format?address=some_address&sensor=true_or_false
And here is an example:
http://maps.google.com/maps/api/geocode/xml?address=Lenox+Hill&sensor=false
The format can be JSON or XML.
You will need to use a Geolocation API (such as Google or Bing or Yahoo), and there might be others as well. But those are the "free" (with caveats) ones that come to mind.
Just remember they have rather strict Terms-of-use of how you can use their API, so be sure you are on the right side of the law.
http://msdn.microsoft.com/en-us/library/cc981067.aspx
http://code.google.com/apis/maps/documentation/
Can you elaborate a bit more on that? What type of application is that? What is the format of the landmark/business? Basically there are geo web services out there that do this kind of stuff...
Have a look at this for example:
http://www.geonames.org/maps/us-reverse-geocoder.html
http://www.geonames.org/export/ws-overview.html
Yahoo http://developer.yahoo.com/geo/geoplanet/guide/concepts.html
You can query for a free-form name such as address, etc, and it will return what is called a WOEID, then query the WOEID for its lat long.

Resources