Is there any Google API to check if an input is a city or not? - google-maps-sdk-ios

Is there any Google API / classes, that can be used to check if a text input is a city or not a city?
I'm developing a real estate iOS app. My app uses GoogleMapSDK for iOS v1.8.1.

if you are just after US cities , there are many places on the internet that you can get every city and zip code for free - like the US Post Office. If you can't store all that or don't want to and really want to use Google - then the exact API you are looking for does not exist. BUT you can actually get the info you want out of the Google API, it will just take some work. It is easy to send the input to Google Geocoding API, then parse the response and see if the response city matches what the user entered. I know... this is not ideal, but there are ways to make it look like it's working the way you want from the user's point of view even though the exact API doesn't exist.

Use place/autocomplete/json API:
It gives a list of response based on query
Simply add "types=(cities)" to your query and Google will return you a list of cities
Use geocode/json API
Good tool to get GPS location from an address (eg. New York)
Simply check the "types" field returned from API, check if it's "locality" or "administrative_area_level_3"
Note: two exceptions are Hong Kong and Macau, MO both are treated as "country" but they are cities

Related

Google geocoding API returns ZERO_RESULTS for postal code

I am trying to geocode user entered data using the Google maps API, and got an error for the Australian postal code "2010"
maps.google.com/maps/api/geocode/json?components=country:AU|postal_code:2010
However, if I search in Google maps, I get a result. Am I doing something wrong in my request?
Your request is completely OK, but unfortunately, Google experience issues with searching 4-digit postal codes. This bug has already been reported in Google issue tracker and you can see it here:
4-digit postal codes are hard to geocode (AT, AU, BE, DK, NZ, SI)
I would suggest starring the bug to add your vote and subscribe to further notifications from Google.
Also you can see that suggested workaround by Google is using place autocomplete request with types (region) and country components filter.
So, in your case you can run the following query
https://maps.googleapis.com/maps/api/place/autocomplete/json?input=2010&types=(regions)&components=country%3AAU&key=YOUR_API_KEY
It will return a place ID for postal code 2010: ChIJ3QyubXuuEmsREIe6P2t9ARw
And you can use geocoding with place ID to get required information
https://maps.googleapis.com/maps/api/geocode/json?place_id=ChIJ3QyubXuuEmsREIe6P2t9ARw&key=YOUR_API_KEY
I hope this helps!
I experienced a similar issue periodically, when geocoding US zip-codes. Appending the country name after the zip-code seemed to fix the problem. So, instead of 60162 use 60162 USA.
When a URL is opened in the browser based on its IP context, it identifies the country and automatically deduces the query format for a zip code is 99.999-99.
The format above is for Brazil, but there are different standards for each country such as USA and Portugal.
One solution when calling an API via CURL, either by code or by terminal, include the "&components = country: US" parameter, changing the "US" country code to what you want to filter.
The Google API returns ZERO_RESULTS for safety, because a search would be too slow and could do a global search worldwide and not just the country. For performance and speed reasons, Google creates this automatic ID for help, but unfortunately is not provided to developers about this process.
Good luck!

Wunderground API - country/state/city mix issue

I'm using Google Maps Place API restricted to cities research, hence I get city, state and country plus conditions and forecast10day Wunderground API.
It seems sometimes I've issues building the Wunderground API endpoint.
When I have a city available in just one country, I've this endpoint:
http://api.wunderground.com/api/{KEY}/conditions/q/IT/Milan.json
and it works like a charm.
When I know the city I'm searching for is available in many countries, I add the "state" value to the endpoint, like this:
http://api.wunderground.com/api/{KEY}/conditions/q/US/PA/Lancaster.json
The issue comes when I search for New Delhi in India (and at this point I'm afraid also for other cities):
http:// api.wunderground.com/api/{KEY}/conditions/q/IN/DL/NewDelhi.json
In this case the response is this:
"error": {
"type": "querynotfound",
"description": "No cities match your search query"
}
But If I call conditions/ for New Delhi in India via "zmw" parameter
http://api.wunderground.com/api/{KEY}/conditions/q/zmw:00000.1.42182.json
I see this in "display_location" object:
"city":"New Delhi / Safdarjung",
"state":"DL",
"state_name":"India",
"country":"IN"
So, it seems that formally my endpoint is right.
What am I going wrong in?
PS: I'm using Google Maps Place API 'cause it's also UI ready. :)
I've contacted the Wunderground tech support.
Well - as they told me - their API is a little bit inconsistent, so for places outside of US, the best solution is to make an API call via lat/lng values, so to ensure always the same response structure.
For me it has been possible 'cause via Google Maps Places I save also lat/lng values for the city I'm searching for.
So, you can build this endpoint:
https://api.wunderground.com/api/{KEY}/conditions/q/{lat},{lng}.json
and it works like a charm!

Google Geocode api returning incorrect result for a particular address

When I try to geocode one of the adress using Google geocode api, Google api returns an incorrect location.
search address : republic of estonia
result from google api: spain
I am using javascript Google api to geocode the address. For some other location the result is correct but for above address its incorrect.
If we enter below url in browser, we get the JSON back and it is showing result somewhere in Spain rather than showing result in Estonia.
http://maps.googleapis.com/maps/api/geocode/json?address=republic%20of%20estonia
I tried same addres in maps.google.com and it takes me to correct location.
Have a look at the Estonia country feature in Map Maker:
https://www.google.com/mapmaker?iwloc=0_0&fmi=0_0&gw=39&fid=5085290329182063613:4677726785527621059&dtab=overview&ll=58.620408,24.93212&spn=3.101226,8.668213&z=7&lyt=large_map_v3&htll=58.560236,25.449737&hyaw=278.7642140009582
If you check the list of names for this feature, you will see that there is no 'Republic of Estonia' in the list. The name is simply 'Estonia'.
The request for 'Estonia' works as expected:
https://maps.googleapis.com/maps/api/geocode/json?address=estonia&key=YOUR_API_KEY
If you believe that 'Republic of Estonia' must be in the list of the names please Send a feedback (bottom right corner) to Google from this page
https://www.google.com/maps/place/Estonia/#58.7223142,23.1414399,7z/data=!4m5!3m4!1s0x4692949c82a04bfd:0x40ea9fba4fb425c3!8m2!3d58.595272!4d25.013607?hl=en
Google assumed you were looking for "Calle Estonia" or "Estonia Street".
You should request that Google add "Republic of Estonia" to their list of spaces. Google, and most other mapping services, only have "Estonia" or "EST" in their list of places.
Also, you may want to use a different API if you need to get an accurate answer. Google is really good, but Google tries to "guess" what you mean and always gives you a result. But, a service like SmartyStreets matches searches to databases of addresses (so if the search is not a "real" place, it will tell you).
(Full disclosure: I have worked for SmartyStreets.)

Google maps GeoCode API doesn't return any result at all?

This is weird. When I search something like "The New York Palace Hotel,America,New York" in Google maps app's search box I get exactly the hotel on the map.
However When I use the maps API,
A GET at http://maps.googleapis.com/maps/api/geocode/json?address=The%20New%20York%20Palace%20Hotel,America,New%20York&sensor=true
I get ZERO results in the response.
It doesn't even give New York as the option in search results.
I am making an app where I use this API to get the lat-long for user provided address.
Now, I don't know why this Google maps API doesn't work the way the Google maps app works.
BUT I wanted to know, is there a way to search and provide Google maps API these search terms as meaningful words where instead of taking whole string as one parameter it knows which city I am searching and which Address I ams searching.
If not, then only option left with me will be to Once the first results fails I make another query for city name only.
recently, i was given a similar task, and came to know the api works reverse... i.e.. we can get address for lat lon that we provide.. and that too has its own restrictions (i.e.. no.of addresses resolved per request, mostly some 2500 address per day something...)....here you can get some info over that...
You are using the Geocoding API. "The New York Palace Hotel,America,New York" is not an address, it is a "place". The Places API might be a better option.
Example of your query using the (javascript version of) the Places API

Region Biasing with Google Maps

My users, who may be located anywhere in the world, will be presented with a text box wherein they can enter their address. In most cases, I assume they will physically be in the same country as whatever address they are typing.
I'd like to help Google Map API make better guesses by doing region biasing. Is there a way to tell Google to region bias from where the request is being made? Or how can I give that information to Google when I make the web service call (e.g. convert IP address to country information)?
Thanks.
The last time I checked, the "region bias" for both the client-side and the server-side Google Geocoder was not reliable. Check out this post from last April (tested again right now, and the issue persists):
Google's Geocoder returns wrong country
The most reliable way that I found is to append the country at the end of the address. Therefore if the user is located in the UK, and types "Oxford Street London", you'd attach ", UK" to the address for geocoding.
To get the country of the user, there are quite a few solutions. You could use the Geolocation API as #You suggested in the other answer, or you may want to use a third party IP-to-location service. You may want to check out MaxMind GeoLite City service, which is free, and is reportedly 99.5% accurate on a country level.
In modern browsers you can use the HTML5 Geolocation API as described in Dive Into HTML5. This assumes client-side support and that you're making the requests client-side. For a server-side (or fallback) solution, you could try something like the PHP Geo IP functions.