Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Openlayers: geocoder error when looking for an unexisting location #116

Closed
ellouis opened this Issue · 6 comments

3 participants

ellouis Jack Cushman b_b
ellouis

With mxn-2.0.18, I get an error when using the Openlayers geocoder with a bogus address: "place.address is undefined"
The script crashes without ever reaching the callback function.

The problem is in mxn.openlayers.geocoder.js, line 77
If 'status' is 200 and 'results' is empty, then place.address.country will crash, since place.address does not exist.

Adding 'if (place.address != null) {' line 77 (closing on line 96) fixes the problem.
There must be a better way. Maybe calling the error_callback.

I have not checked if the problem also exists other providers.

Here's some code to trigger the error:

var geocoder = new mxn.Geocoder('openlayers',geocodeSuccess);
var searchAddress = {address: 'mouirp'};
geocoder.geocode(searchAddress);
Jack Cushman

I just came here to report the same thing. The problem is when you ask OpenLayers for a non-codable address, it returns an empty array with status 200 instead of returning an error status. My solution was to add this else if at line 61:

        if (status != 200) {
            this.error_callback(response.statusText);
        }
        else if (results instanceof Array && !results.length){
            this.error_callback("OpenLayers didn't recognize this address.");
        }
        else {
...

But maybe there's a better way?

b_b
Owner

Ok i see the bug, could you open a pull request with your attached code ? This seems fine to me for mergin.

I will open an issue on Nominatim trac about this, maybe it will be fixed in the future.

++

ellouis

jcushman, Your version is better than mine. Go for it.

Jack Cushman

OK, should be sent.

b_b
Owner

Issue for Nominatim is there : https://trac.openstreetmap.org/ticket/4304

b_b
Owner

i've merged the associated pull request #118, thanks for the fix ++

b_b brunob closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.