Geocoder returns "status OK" even when address not found

764 views
Skip to first unread message

waldo22

unread,
Dec 6, 2011, 5:27:20 PM12/6/11
to google-map...@googlegroups.com
I am trying to geocode addresses to determine whether or not they are in our delivery area for our service.

For most addresses, it is working just fine;  It either informs the customer that they are outside of our delivery area, or it sets their zone and allows them to continue.

However, sometime in the last 6 weeks the API stopped working and no longer returns ZERO_RESULTS for non-existent addresses as described here:
http://code.google.com/apis/maps/documentation/javascript/services.html#GeocodingStatusCodes

If I use an address such as 123 Nowhere St. or 34 Gobbledygook Ln. or 44 Bullhockey Rd., I get a status of "OK" and a LatLng object with the coordinates of the city center.

This means that anyone can type in any fake address and be treated as if they were inside our area.

For example, 123 Nowhere St. Durham, NC returns (35.9940329, -78.898619) which is the same result as typing "Durham, NC" into maps.google.com.

Here is a link to the page displaying this behavior:
https://www.scratchtakeout.com/cgi-bin/geocodeTest.pl

(note:  I have it set to alert(status + ' ' + google.maps.GeocoderStatus.OK) for debugging - both always show up as "OK")

Here is my full code:

 var geocoder; //this is global      
 
function initialize() {
        geocoder = new google.maps.Geocoder();
    }

    function loadScript() {
      var mapScript = document.createElement('script');
      mapScript.type = 'text/javascript';
      mapScript.src = 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initialize';
      document.body.appendChild(mapScript);
    }
 
function codeAddress() {
        var address = document.getElementById('streetAddress').value;
        var city = document.getElementById('city').value;
        var state = document.getElementById('state').value;

        if (address === '') {
            alert('You must enter a street address!');
            return false;
        }

        address = address + ' ' + city + ' ' + state;

        geocoder.geocode( { 'address': address}, function(results, status) {
          if (status == google.maps.GeocoderStatus.OK) {
            alert(status + ' ' + google.maps.GeocoderStatus.OK);
            //whichZone(results[0].geometry.location);
            return true;
          } else {
            showLightbox(320,130,'10px','notFoundChoice');
            document.getElementById('tryAgain').focus();
            return false;
          }
        });
    }

Does anyone know why the JS V3 API would return a status of "OK" even for a non-existent address?

It certainly used to work - and I haven't changed anything that I can remember.

Any help is appreciated!

-Wes
 

JKurtock

unread,
Dec 6, 2011, 8:55:35 PM12/6/11
to Google Maps JavaScript API v3
While this is not exactly your problem, your subject line talks about
non-existent addresses.

There may be a house located on 123 Main Street, and right next door
is 127 Main Street. If you attempt to geoCode 125 Main Street, the
Service will return a result (if you're lucky, it will be labelled
"Range Interpolated," but you can't even count on that 100% of the
time). Even though there is no house there.

So if you're trying to determine whether you can deliver a Pizza to
125 Main street, this isn't perfect.

The USPS has an address verification service. It will tell you that
125 Main street probably is no good (for purposes of mail delivery,
and who should know better?) But it might also tell you that 123 Main
Street is no good (because they receive their mail on the cross street
at 201 Elm St.) Here, it might be safe to deliver a Pizza to 123 Main
Street (they have a door there) even though it is not their mailing
address.

GeoCoding requires a lot of thinking.

- Jeff

On Dec 6, 2:27 pm, waldo22 <w...@tarheeltakeout.com> wrote:
> I am trying to geocode addresses to determine whether or not they are in
> our delivery area for our service.
>
> For most addresses, it is working just fine;  It either informs the
> customer that they are outside of our delivery area, or it sets their zone
> and allows them to continue.
>

> *However*, sometime in the last 6 weeks the API stopped working and no
> longer returns ZERO_RESULTS for non-existent addresses as described here:http://code.google.com/apis/maps/documentation/javascript/services.ht...


>
> If I use an address such as 123 Nowhere St. or 34 Gobbledygook Ln. or 44
> Bullhockey Rd., I get a status of "OK" and a LatLng object with the
> coordinates of the city center.
>

> This means that anyone can type in *any* *fake* address and be treated as


> if they were inside our area.
>
> For example, 123 Nowhere St. Durham, NC returns (35.9940329, -78.898619)
> which is the same result as typing "Durham, NC" into maps.google.com.
>
> Here is a link to the page displaying this behavior:https://www.scratchtakeout.com/cgi-bin/geocodeTest.pl
>
> (note:  I have it set to alert(status + ' ' +
> google.maps.GeocoderStatus.OK) for debugging - both always show up as "OK")
>
> Here is my full code:
>
>  var geocoder; //this is global
>
>
>
>
>
>
>
>
>
> > function initialize() {
> >         geocoder = new google.maps.Geocoder();
> >     }
>
> >     function loadScript() {
> >       var mapScript = document.createElement('script');
> >       mapScript.type = 'text/javascript';
> >       mapScript.src =

> > 'http://maps.googleapis.com/maps/api/js?sensor=false&callback=initiali...

waldo22

unread,
Dec 7, 2011, 11:25:18 AM12/7/11
to google-map...@googlegroups.com
Jeff,

Thanks for your thoughtful reply.

(and apologies for the double-post, I didn't realize that new topics had to be "approved" and I re-posted).

Based on helpful suggestions, we are now checking for "ROOFTOP" or "RANGE_INTERPOLATED" results, and this seems to suit our needs.

It doesn't need to be perfect, we just need to be able to find the general area that the location is in.

I do not think that the API should return a status of "OK" for an address when the entire street doesn't exist, however.

It didn't do this a few months ago, at least.

Thanks for your help,

-Wes

Barry Hunter

unread,
Dec 7, 2011, 12:43:58 PM12/7/11
to google-map...@googlegroups.com
>
> Based on helpful suggestions, we are now checking for "ROOFTOP" or
> "RANGE_INTERPOLATED" results, and this seems to suit our needs.

That is restricting yourself to pretty much exact matches on the address.

>
> It doesn't need to be perfect, we just need to be able to find the general
> area that the location is in.

So in fact you do accept inexact results. Not caring if it an exact
address match?

The two statements seem contradictory?


>
> I do not think that the API should return a status of "OK" for an address
> when the entire street doesn't exist, however.


One of the uses for the geocoder, is to allow the user to center the
map on their location.

One of the reason the street may not exist is simply that 1) it not in
googles database yet at all, or 2) there is some typo or some other
reason it was not exactly matched.

... in which case getting the 'part' match, of the general area, can
be a useful feature - the user can then manually zoom to the right
area. Rather than just getting a hard 'fail' and have to start from
scratch anyway.

Pretty sure there used to be an explicit option, if you would accept
part matches, but its probably not reliable. So examining the results
to see if they are good enough quality for your usecase is better,
than just expecting the geocoder to use some predefined 'quality
level' which might or might not match your usecase.

Reply all
Reply to author
Forward
0 new messages