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

ellouis opened this Issue Mar 14, 2012 · 6 comments

3 participants


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 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'};

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) {
        else if (results instanceof Array && !results.length){
            this.error_callback("OpenLayers didn't recognize this address.");
        else {

But maybe there's a better way?


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.



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


OK, should be sent.


Issue for Nominatim is there :


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

@brunob brunob closed this Apr 5, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment