Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Google geocoding service returns response for fake address

I'm using the google geocoding service to validate that a city name (plus region and country) that has been entered in our system exists, and to get the lat/long.

However, I'm finding that it seems to 'guess' if you make a typo, and returns an response even if you made an error.

For instance, a request for "Beverton, Ontario, Canada" returns the lat/long for Beaverton, with no indication that you provided the wrong city name.

I'm using the CSV response type, and am getting the 200 response code.

Can I either prevent the service from doing this, or, better yet, find out if it has?

Edit: to clarify ... Google is correcting the input (when I would expect it to just fail) and I need to know if it has done this.

like image 729
Buzz Avatar asked Jul 21 '09 19:07

Buzz


People also ask

What does geocode return?

For example, a geocode of "Chicago" returns "locality" which indicates that "Chicago" is a city, and also returns "political" which indicates it is a political entity. formatted_address is a string containing the human-readable address of this location. Often this address is equivalent to the postal address.

How are addresses geocoded?

Geocoding relies on a computer representation of address points, the street / road network, together with postal and administrative boundaries. Geocode (verb): provide geographical coordinates corresponding to (a location).

Does Google Maps use geocoding?

The Google Maps APIs have several services that you can use to convert addresses into coordinates - the Geocoding API, the Place Autocomplete service in Places API, and the Place Search service in Places API.


1 Answers

There isn't any way for the geocoder to let you know if it thinks you had a typo. I agree with Saul's answer, that your best bet is to check your query against the response.

I just wanted to point out that you'll have to check several elements of your input against several of the response values, in order to find the elements that should match up. In this case, "Beaverton" was found inside of "DependentLocalityName".

<?xml version="1.0" encoding="UTF-8" ?>
<kml xmlns="http://earth.google.com/kml/2.0"><Response>
  <name>Beverton, Ontario, Canada</name>
  <Status>
    <code>200</code>
    <request>geocode</request>
  </Status>
  <Placemark id="p1">

    <address>Beaverton, Brock, ON, Canada</address>
    <AddressDetails Accuracy="4" xmlns="urn:oasis:names:tc:ciq:xsdschema:xAL:2.0"><Country><CountryNameCode>CA</CountryNameCode><CountryName>Canada</CountryName><AdministrativeArea><AdministrativeAreaName>ON</AdministrativeAreaName><SubAdministrativeArea><SubAdministrativeAreaName>Durham Regional Municipality</SubAdministrativeAreaName><Locality><LocalityName>Brock</LocalityName><DependentLocality><DependentLocalityName>Beaverton</DependentLocalityName></DependentLocality></Locality></SubAdministrativeArea></AdministrativeArea></Country></AddressDetails>
    <ExtendedData>
      <LatLonBox north="44.4502166" south="44.4183470" east="-79.1199562" west="-79.1839858" />
    </ExtendedData>

    <Point><coordinates>-79.1519710,44.4342840,0</coordinates></Point>
  </Placemark>
</Response></kml>

Update:

This may be impossible to actually implement. If your input is "Beverton, Ontario, Canada", how do you know which of those three words to check for? Two of them will match up just fine. What if they're entered in a different order?

like image 169
Chris B Avatar answered Oct 21 '22 07:10

Chris B