google maps api geocoding is less precise than manual search, why? - google-maps

i am using a php script (followed this tutorial http://www.bitconsultants.net/2010/geocoding-with-google-maps-and-the-zend-framework/) to get the latitude and longitude of different adresses,
the problem is that if i manually search an address in google maps it gives me the right location,
while using the php script, the json response from google is even 500meters away from the manual search result, which makes it kind of pointless for my needs...
i am passing the address in this format
$address = "{$data['street']}, {$data['postcode']}, {$data['city']}, {$data['province']}";
and i am passing google a key
thank you

Are your addresses really well formed? Could you please give a concrete example?
Such difference could occur if the postal address is not found at given city or town and Google tries to partially match the given address. See *partial_match* on API documentation.
Also: unfortunately the link you gave above does not work here ("Forbidden" error).

i found out why, don't use php urlencode() on the $address, it does something strange with "," and maybe other stuff, so google doesn't understands well your url

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!

Address validation via Google Maps API

I want to send an address via Google API and get a response if this is a valid or wrong address. If it's a wrong address the response will include the reason (e.g. wrong zip code, wrong state etc.)
Is it possible?
Thanks
Google Maps APIs are not intended for address validation. They do, however, provide a variety of other services including geolocation, directions, distance calculation, and much more. For a list of APIs as well as what they can do for you please check out the API Picker here:
https://developers.google.com/maps/documentation/api-picker
I hope this helps!

Link to street view URL using address?

Is it possible to link directly to street view from an URL using only the address (and not lat/lng)?
For example, is there a way to do something like
http://maps.google.com/maps?q=&layer=c&address=Street,number,state&cbp=11,0,0,0,0
Instead of
http://maps.google.com/maps?q=&layer=c&cbll=31.335198,-89.287204&cbp=11,0,0,0,0
?
Lat/lng from geocoding tends to not be recognized by street view as being too far from a street, sometimes getting the wrong street altogether, because the lat/lng it generates may be off the street, as it tries to match the location of a house.
I have looked everywhere and even tried playing with google's URLs on my own, but I can't find anything on it. Most sources won't even mention address. I'm currently using the url sample from this question, but it still isn't really what I'm looking for.
If this is really not possible, could someone link to a source/documentation where it says so?
Edit: Thank you everyone for the answers, but none really address the issue with street view and addresses. I'll look into forwarding this to google. I'll post here if I get a reply.
Let's enhance your code, if you paste the code in browser then you will be redirect to google maps and will show result what you requested.
http://maps.google.com/maps?&q=Space+Needle,Seattle+WA
If you would like to pass the value (address) via php or any other code type then simply it will not work, you cannot use google maps without API to enhance your requirement. Lat & Lng is basic practice to show map and not require any api, but if you would like to pass additional properties then you will have to use google maps api to do so. Detailed documentation can be found here
https://developers.google.com/maps/documentation/embed/guide
but let's try an example try this code in browser
https://www.google.com/maps/embed/v1/place?q=Mumbai,+Maharashtra,+India
You will get an error that api key not found but if you try this one
https://www.google.com/maps/embed/v1/place?key=AIzaSyD4iE2xVSpkLLOXoyqT-RuPwURN3ddScAI&q=Space+Needle,Seattle+WA
Then you will get output. Hope it helps!
First reverse geocode to find the lat lng using another Google Service API.
Then feed the resulting lat lng into the streetview endpoint parameter.

Getting correct address from user typed street address using google maps

I've never used the google-maps api, but I just want to do one particular thing.
I've got around 1000 user typed street addresses. Some are missing states and postcodes. I've noticed if I type these addresses into google maps it generally gives me back the state and postcode (only very rarely it gives some options). Is there a way to do this programatically, so I don't have to manually copy/paste this in? Has someone already made an application/library to do this that I can just feed the user typed data to?
Edit:
I've noticed this does the job:
https://maps.google.com.au/maps?q=1%20George%20st%20sydney
It returns state and postcode. But it returns it on a webpage with a whole lot of other stuff. I just want the address only. I guess I could grep through the results, but some additional thing to add to the query string so it only returns the raw address (or some structure) would be useful.
You can use the Geocoding API - https://developers.google.com/maps/documentation/geocoding/
E.g. http://maps.googleapis.com/maps/api/geocode/json?sensor=false&address=1%20George%20st%20sydney ; you can replace "json" with "xml" if you prefer. Look for "formatted_address" in the result, or individual address components, depending on what you need.
However, I'm quite frustrated that it sometimes doesn't work, even for some cases where the regular google maps search is successful.

Google Maps API - Get Coordinates of address

I would like to convert addresses into long/lat.
Is there any way to do this without using JavaScript? Because in my case there is no need to display anything since the conversion is in the background.
What you are looking for is called Geocoding.
Google provides a Geocoding Web Service which should do what you're looking for. You will be able to do geocoding on your server.
JSON Example:
http://maps.google.com/maps/api/geocode/json?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
XML Example:
http://maps.google.com/maps/api/geocode/xml?address=1600+Amphitheatre+Parkway,+Mountain+View,+CA
Edit:
Please note that this is now a deprecated method and you must provide your own Google API key to access this data.
Althugh you asked for Google Maps API, I suggest an open source, working, legal, free and crowdsourced API by Open street maps
https://nominatim.openstreetmap.org/search?q=Mumbai&format=json
Here is the API documentation for reference.
Edit: It looks like there are discrepancies occasionally, at least in terms of postal codes, when compared to the Google Maps API, and the latter seems to be more accurate. This was the case when validating addresses in Canada with the Canada Post search service, however, it might be true for other countries too.
Geocoding through Javascript:
https://developers.google.com/maps/documentation/javascript/geocoding
A Nuget solved my problem:Geocoding.Google 4.0.0.
Install it so not necessary to write extra classes etc.
https://www.nuget.org/packages/Geocoding.Google/