Region Biasing with Google Maps - 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.

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!

Is there any Google API to check if an input is a city or not?

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

Is it possible to track a google map location using landline phone number?

I want to locate a location on the google map using phone number. Is it possible? If yes, what is the parameter which I need to append in the request url. As of now, I am appending 'address' and my URL is
http://maps.googleapis.com/maps/api/geocode/json?address=THE+FRENCH+LAUNDRY&sensor=false
As long as I know, this is not possible with Google Maps (but maybe someone else knows more...). In some country, like Italy (where I live), it could even be against the law (depending on a few legal parameters).
Despite this, I saw some user here in SO signalling that some applications developed and managed by Google and installed on Android devices seem to be able to do so (in the countries where this is legal, of course). Most likely, these apps use a Google online database that is not accessible to the common user/developer.
Moreover, there are other companies that offer location services that can locate a user both if he/she uses a cellular phone and if he/she uses a land line one (in the countries where this is legal).

Can I use the Google Maps API to find out of a house is in a particular town?

I am developing an Estate Agents website. Each property has it's geolocation code saved in a database. Visitors will want to search for properties in a given location (say a town like "Southampton"). Could Google's Maps API (web services) help me with this?
I've seen this facility provided on other Estate Agent's website but I don't know how they do it.
You definetly can. Through Google Maps WebService API you can decode your geolocation into readable address, and the perform a search on it.
If I were you, I'd save locally not only the geolocation, but also the address, better if decomposed in pieces (like Country, Region, City, and so on).
Here you can find the official documentation
http://code.google.com/intl/it-IT/apis/maps/documentation/webservices/
This is basically a standard "store locator" problem -- except your "stores" are properties. The user enters their search term, say "Southampton"; you geocode that and then find the targets which are within your chosen distance of that location. There are plenty of examples, including in the documentation: http://code.google.com/apis/maps/articles/phpsqlsearch_v3.html

Geocoding with Google Maps API - accuracy and limitations

It is easy to use the Google Maps API to find a specific street address and return the latitude and longitude. For example, link.
However, it appears that typing in the name of a specific location, for example a park, causes problems. Often these don't have a specific street number (at least, not easily findable). Despite the fact that Cadigal Reserve is located at the same address as in the link above, if I enter that as part of the query string and remove the street number, the results become rather useless: link
Typing this directly into maps.google.com easily finds the park itself (and of course, you could then find the latitude/longitude by looking in the URL).
Is there not any way of using the Google Maps API to geocode a park location like this?
It is important to understand that geocoding is not an exact science. The recommended practice if you have addresses that you know should geocode to a specific location is to build a cache and use local (client-side) geocoding.
In version 2 of the api you would build your own client-side cache that contains pre-computed geocoder responses by extending the GeocodeCache. Once a cache is defined, you would call the setCache() method and away you go. This is pretty much explained here:
http://code.google.com/apis/maps/documentation/javascript/v2/services.html#Geocoding_Caching
However, AFAIK GeocodeCache was removed in V3 of the api...
So, I would suggest implementing your own client -side caching-strategy of known addresses and their corresponding coordinates. When your application receives a geocode request for a known address the response would come from your cache (rather than Google's geocoding servers).
Failing all that you can always use a payed geocoding service that, in theory, will have a much more accurate dataset (as well as a higher limit on requests, etc).
Finally, you should also take a look through the Geocoding Strategies document as it gives a good handle on some of the issues here.