1

Working with Leaflet Control Search. I would like to add a timeout function to the marker that is added to the map if a location is found.

Any ideas in which line I have to add "setTimeout" function?

I tried

showLocation: function(latlng, title) { 

    if(this.options.zoom)
        this._map.setView(latlng, this.options.zoom);
        this._map.panTo(latlng);                                                       

    if(this._markerLoc)
    {
        this._markerLoc.setLatLng(latlng);  
        this._markerLoc.setTitle(title);
        this._markerLoc.show();
        this._markerLoc.bindPopup(title);
        this._markerLoc = setTimeout(function() {
        this._markerLoc.hide()
        },1000);
        if(this.options.animateLocation)
            this._markerLoc.animate();

    }

    if(this.options.autoCollapse)
        this.collapse();
    return this;
}});

The result: marker still shows up...

closed as off-topic by nmtoken, Evil Genius, ArMoraer, whyzar, Midavalo Jan 13 '17 at 15:19

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Questions seeking help to debug/write/improve code must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself. Providing a clear problem statement and evidence of a code attempt will help others to help you. See: How to create a Minimal, Complete, and Verifiable example." – nmtoken, Evil Genius, ArMoraer, whyzar, Midavalo
If this question can be reworded to fit the rules in the help center, please edit the question.

  • 4
    Please post some of your Leaflet code to show what you have tried, and what isn't working as expected. An image might help too. – nmtoken Jan 13 '17 at 11:26
1

You should be able to use something along the lines of setTimeout, e.g.

setTimeout(function() {
        // hide marker
    }, 1000);
  • 1
    Thanks it worked! Just a short advice: not remove marker but marker.hide() is correct. – howard.D Jan 19 '17 at 12:00

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