Activity Forums Salesforce® Discussions How to get the state and country name when we click on the map, using Leaflet JS in Salesforce?

  • How to get the state and country name when we click on the map, using Leaflet JS in Salesforce?

  • Gourav

    Member
    March 21, 2018 at 3:12 pm

    Is there a way to get the state and country name when we click on the map, using Leaflet JS in Salesforce?

  • PRANAV

    Member
    March 27, 2018 at 11:54 am

    Hi Gourav,

    The click function method is as below.

    map.on('click', function(e){
    $.ajax({ url:'http://maps.googleapis.com/maps/api/geocode/json?latlng='+e.latlng.lat+','+e.latlng.lng+'&sensor=true',
    success: function(data){
    var state = data.results[0].address_components[5].long_name;
    var country = data.results[0].address_components[6].long_name;
    var zip = data.results[0].address_components[7].long_name;
    $('.leaflet-popup-content').text(state+' '+country+' '+zip);
    console.log(data.results[0]);
    }
    });
    popup.setLatLng(e.latlng).setContent('').openOn(map);
    });

    Hope this helps you.

Viewing 1 - 2 of 2 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos