1

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.

1 Answer 1

1

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

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

to

        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.setValue(value);
            p.fire('reversegeocoded', {waypoint: wp, value: value});
        })

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.