Activity Forums Salesforce® Discussions How 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.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos