Skip to content Skip to sidebar Skip to footer

Mapbox - How To Display Lat And Lng Coordinates Inside A Div After Select Address Inside A List

I'm using MapBox on my application and i would like to know how can i display lat and lng inside div element after i select an address from a list that are display inside a div? My

Solution 1:

If I'm understanding you well, what you want is basically capture the result selected in the geocoder and paint the coordinates of the result in a div. For that, you need to subscribe to the result event.

For that, you need to add the event listener like this, and there paint the result in the inner HTML of the div:

    geocoder.on('result', function(r) {
      console.log(r);
      document.getElementById("coords").innerHTML = r.result.center;
    })

I have created a fiddle on how to subscribe to result selected on geocoder

enter image description here

PS: If this answer solves your question, please mark it as answer accepted, in that way it will help other users to know is the right solution.

Post a Comment for "Mapbox - How To Display Lat And Lng Coordinates Inside A Div After Select Address Inside A List"