I am using the combination of:

  • OpenStreetMaps

  • Leaflet.js

  • Leaflet Routing Machine + lrm-tomtom plugin (routing done using TomTom API)

and now I have decided to switch from Nominatim geocoder (which is default in LRM) to OpenCageData geocoder. They do have plugin for Leaflet, works fine except one minor thing:

When I drag the marker to change the route, the geocoder input is updated in form of coordinates, like on the image below, whereas Nominatim updates the place name automatically.

enter image description here

Is there any way to implement same functionality for OpenCageData geocoder? I guess there should be but haven't figured that out yet.


Eventually found a workaround, in the LRM changed the default _update: function() code

    var wp = this._waypoint,
    value = wp && wp.name ? wp.name : '';
    this.fire('reversegeocoded', {waypoint: wp, value: value});


        var wp = this._waypoint,
            value = wp && wp.name ? wp.name : '';
        var g = L.Control.OpenCageSearch.geocoder({key: "my-key", limit: 1});
        var q = this._waypoint.latLng.lat+','+this._waypoint.latLng.lng;
        var p = this;
        g.geocode(q, function(r) {
            if (r.length > 0) {
                wp.name = value = r[0].name;
            p.fire('reversegeocoded', {waypoint: wp, value: value});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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