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

Pros & Cons of Lightning Component vs. 3rd party frameworks in Salesforce UI development

Video in

Nikita drops by to share his invaluable experience of using popular 3rd party frameworks in Salesforce. http://media.blubrry.com/salesforceway/audio.xmcdn.com/group42/M05/25/57/wKgJ81rXk6XjaZIAAU_I_KtprFM998.m4a