1
votes

I've been using Mapbox on a project with the geocoder feature. Sometimes a result from the geocoder will not have bounds defined. The event handler that fires as soon as a user selects a location from the geocoder's menu tries to zoom+center on those bounds.

The expected result would be to at least center the map onto the available latlng which is always available.

The actual result is that nothing happens. In fact, Mapbox throws an error, and because of that error, my own event handler on the select event won't fire either.

// Mapbox vars
var map, geocoder;

// Event handlers
function foundHandler(args){
    console.group('found');
    console.log(args);
    console.groupEnd();
}

function selectHandler(args){
    console.group('select');
    console.log(args);
    console.groupEnd();
}

// Init Mapbox
geocoder = L.mapbox.geocoder('examples.map-vyofok3q');
map = L.mapbox.map('map', 'examples.map-9ijuk24y')
.addControl(
    L.mapbox.geocoderControl('examples.map-vyofok3q', {})
    .on('found',foundHandler)
    .on('select',selectHandler)
    );

http://jsfiddle.net/rgbk/rCjS4/1/

To reproduce

  1. Search "Boston" and note the console. Results will have bounds. The custom "select" event handler will fire
  2. Search "Topsail NC". results that do not have bounds. The custom "select" event handler will not fire.
2

2 Answers

0
votes

Is this a bug report? That geocoding API is in beta. You may want to report your findings to [email protected].