Question

I just discovered a strange behavior in Google Maps API V3, and more specifically with its Geocoding tool.
Here is an exemple : This is how I geocode my addresses :

var request = HttpWebRequest.Create(@"http://maps.googleapis.com/maps/api/geocode/json?address=" + address + "&sensor=false");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();

where address is a varible with a full address entered by the user.

When the address is a valid one, response.StatusCode is OK, which means, according to the documentation, "that no errors occurred; the address was successfully parsed and at least one geocode was returned."
But when the try to geocode this adress :

15 StreetWhoDoesntExist, 69009 LYON

the StatusCode is OK and the latitude / longitude returned is the center of the city (in this example, LYON, which is a real French city and its corresponding zipcode, 69009).

Is this behaviour normal ? When I entered the same address in Google Maps, it told me it can't find this address (which is the "good" behavior). So, how can I reproduce it with GMaps API in order to it refuses addesses with an unknown street name, even if the associated city and/or zipcode exists ?

Thanks in advance !

Was it helpful?

Solution

API CALL

Result:

     "partial_match" : true,
     "types" : [ "sublocality", "political" ]

So I'd check those two or at least the types to determine if it found the actual street address.

OTHER TIPS

Yes that is normal. There was a result returned, just not the one you were expecting. If you go a bit further down in the documentation you will see this:

  • geometry contains the following information:
    • location contains the geocoded latitude, longitude value. For normal address lookups, this field is typically the most important.
    • location_type stores additional data about the specified location. The following values are currently supported:
      • "ROOFTOP" indicates that the returned result is a precise geocode for which we have location information accurate down to street address precision.
      • "RANGE_INTERPOLATED" indicates that the returned result reflects an approximation (usually on a road) interpolated between two precise points (such as intersections). Interpolated results are generally returned when rooftop geocodes are unavailable for a street address.
      • "GEOMETRIC_CENTER" indicates that the returned result is the geometric center of a result such as a polyline (for example, a street) or polygon (region).
      • "APPROXIMATE" indicates that the returned result is approximate.

You will need to check the location_type to see how "accurate" the result returned is. In your case the geocoder was unable to find 15 StreetWhoDoesntExist, so the next best result was the center of the zipcode.

The address_components[] that are also returned with the geocode result has additional information you can use to get a better understanding of what is coming back.

The partial_match parameter will let you know if the geocoder did not return and exact match. This will ususally be true with misspellings or missing address parts.

The reason maps.google.com rejects the address is because they have custom logic built into their application that is catching these types of results. The geocoder just returns the raw result, you need to write business logic to handle those results.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top