What is the best way to modify the searchbox listener searchbox in the CartoDB map?

I would like to disable the default event listener for the CartoDB searchbox and first to execute my own listener and then decide If I want to execute the default CartoDB event (geolocation) for the searchbox.

How is the best way to do it?

I this is not possible can I add a second input text box in the map?

For now I am using $(".cartodb-map-wrapper").append(' '); but I don't know if this is the best thing.

1 Answer 1


You need to extend the funcitonality of the Searchbox. In the following example, I attach the ', British Columbia, Canada' text to it by default.

You can check the example here: http://bl.ocks.org/iriberri/05e6feec84f12ab362df

Copying it also here for the record:


  cdb.geo.ui.Search = cdb.geo.ui.Search.extend({

    _submit: function(ev) {

      var self = this;
      var address = this.$('input.text').val() + ', British Columbia, Canada';

      // Show geocoder loader

      cdb.geo.geocoder.NOKIA.geocode(address, function(coords) {
        if (coords.length>0) {
          var validBBox = true;

          // check bounding box is valid
          if(!coords[0].boundingbox || coords[0].boundingbox.south == coords[0].boundingbox.north ||
            coords[0].boundingbox.east == coords[0].boundingbox.west) {
            validBBox = false;

          if (validBBox && coords[0].boundingbox) {
          } else if (coords[0].lat && coords[0].lon) {
            self.model.setCenter([coords[0].lat, coords[0].lon]);

        // Hide geocoder loader


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.