{"id":1894,"date":"2020-05-01T14:53:32","date_gmt":"2020-05-01T14:53:32","guid":{"rendered":"https:\/\/www.emizentech.com\/blog\/?p=1894"},"modified":"2022-01-21T11:44:03","modified_gmt":"2022-01-21T11:44:03","slug":"create-salesforce-lightning-map-component","status":"publish","type":"post","link":"https:\/\/multisitelocal.ezxdemo.com\/blog\/create-salesforce-lightning-map-component.html","title":{"rendered":"How to Create a Salesforce Lightning Map Component?"},"content":{"rendered":"<p>We have all tried to integrate different map APIs in salesforce, most popular being Google Map API. Although we have done a spectacular job while using it, how about using inbuilt functionality that Salesforce provides us with. Let us proceed with Lightning Map Component and how we can put it to our use.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Lightning_Map_Component_Attributes\"><\/span>Lightning Map Component Attributes<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>We shall begin with the attributes used in lightning:map component, which are listed below:<\/p>\n<ul>\n<li><strong>class<\/strong> \u2013 It is a CSS class for the outer element, in addition to the component&#8217;s base classes.<\/li>\n<li><strong>title<\/strong> \u2013 It displays us tooltip text on mouse hovers the element.<\/li>\n<li><strong>zoomLevel<\/strong> \u2013 It denotes the zoom levels corresponding with Google Maps API. If it is not specified, the map component automatically defines it according to the screen.<\/li>\n<li><strong>mapMarkers(Required)<\/strong> \u2013 It defines an array of objects with address\/coordinates to be displayed on the map.<\/li>\n<li><strong>markersTitle<\/strong> \u2013 It provides the heading title for the markers when the map has multiple markers. The title is displayed as a header for the list of clickable addresses.<\/li>\n<li><strong>center<\/strong> \u2013 It defines the center location for a map, if not defined it is automatically adjusted.<\/li>\n<li><strong>showFooter<\/strong> \u2013 A link is displayed &#8216;Open in Google Maps&#8217; in the footer which can open a window externally with the markers in the map.<\/li>\n<li><strong>listView<\/strong> \u2013 It displays or hides the list of locations.<\/li>\n<\/ul>\n<h4>Also Read: <a href=\"https:\/\/multisitelocal.ezxdemo.com\/blog\/salesforce-surveys-configuration.html\" target=\"_blank\" rel=\"noopener\">How to Create and Use Salesforce Surveys<\/a><\/h4>\n<h2><span class=\"ez-toc-section\" id=\"Lets_understand_with_given_below_example\"><\/span>Let\u2019s understand with given below example<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Here is what we are trying to as example, we will display the location of Account through the defined billing address. So here is the code:<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Apex_Controller\"><\/span>Apex Controller:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code class=\"d-block\">public with sharing class AccountMapController {<br \/>\n@AuraEnabled<br \/>\npublic static Account getAccountLocation(string accountId){<br \/>\nreturn [Select Id,Name,Website,BillingStreet,BillingCity,BillingState from Account where Id =: accountId];<br \/>\n}<br \/>\n}<br \/>\n<\/code><br \/>\n<a href=\"https:\/\/multisitelocal.ezxdemo.com\/contact-us.html?utm_source=blog&amp;utm_medium=banner&amp;utm_campaign=emizen_blog\"><img fetchpriority=\"high\" decoding=\"async\" class=\"aligncenter wp-image-2232 size-full\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2020\/05\/hire-salesforce-developers.png\" alt=\"hire salesforce developers\" width=\"1310\" height=\"210\" \/><\/a><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Lightning_Component\"><\/span>Lightning Component:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code class=\"d-block\">&lt;aura:component implements=\"flexipage:availableForRecordHome,force:hasRecordId\"<br \/>\naccess=\"global\" controller=\"AccountMapController\"\/&gt;<br \/>\n&lt;!-- attributes --&gt;<br \/>\n&lt;aura:attribute name=\"accountLocation\" type=\"Object\"\/&gt;<br \/>\n&lt;aura:attribute name=\"zoom\" type=\"Integer\" \/&gt;<br \/>\n&lt;aura:attribute name=\"recordId\" type=\"String\" \/&gt;<\/code><\/p>\n<p>&lt;!&#8211; handlers&#8211;&gt;<br \/>\n&lt;aura:handler name=&#8221;init&#8221; value=&#8221;{! this }&#8221; action=&#8221;{!c.initialize }&#8221;\/&gt;<\/p>\n<p>&lt;!&#8211; the map component &#8211;&gt;<br \/>\n&lt;aura:if isTrue=&#8221;{!v.accountLocation.length &gt; 0}&#8221; &gt;<br \/>\n&lt;lightning:map mapMarkers=&#8221;{! v.accountLocation }&#8221; zoomLevel=&#8221;{!v.zoomLevel}&#8221; \/&gt;<br \/>\n&lt;\/aura:if&gt;<br \/>\n&lt;\/aura:component&gt;<\/p>\n<h4>Learn More: <a href=\"https:\/\/multisitelocal.ezxdemo.com\/blog\/salesforce-commerce-cloud-benefits.html\" target=\"_blank\" rel=\"noopener\">Benefits of Salesforce Commerce Cloud Implementation<\/a><\/h4>\n<h2><span class=\"ez-toc-section\" id=\"Lightning_Component_Controller\"><\/span>Lightning Component Controller:<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><code class=\"d-block\"><br \/>\n({<br \/>\ninitialize : function(component, event, helper) {<br \/>\nvar recordId = component.get('v.recordId');<br \/>\nvar action = component.get('c.getAccountLocation');<br \/>\naction.setParams({<br \/>\n'accountId' : recordId<br \/>\n});<br \/>\naction.setCallback(this,function(res){<br \/>\nvar state = res.getState();<br \/>\nif(state==='SUCCESS'){<br \/>\nconsole.log(res.getReturnValue());<br \/>\nvar acc = res.getReturnValue();<br \/>\ncomponent.set('v.accountLocation', [<br \/>\n{<br \/>\nlocation: {<br \/>\nStreet: acc.BillingStreet,<br \/>\nCity: acc.BillingCity,<br \/>\nState: acc.BillingState<br \/>\n},<br \/>\ntitle: acc.Name,<br \/>\ndescription: acc.Website<br \/>\n}<br \/>\n]);<br \/>\ncomponent.set('v.zoom', 16);<br \/>\n}<br \/>\n});<br \/>\n$A.enqueueAction(action);<br \/>\n}<br \/>\n})<br \/>\n<\/code><\/p>\n<h2><span class=\"ez-toc-section\" id=\"Output\"><\/span>Output<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p><img decoding=\"async\" class=\"aligncenter wp-image-1934\" src=\"\/blog\/wp-content\/uploads\/sites\/2\/2020\/04\/lightning-component-output-1024x323.png\" alt=\"lightning component output\" width=\"1000\" height=\"315\" \/><br \/>\nWe at Emizentech are adept at providing <a href=\"https:\/\/multisitelocal.ezxdemo.com\/salesforce.html\">salesforce development services<\/a> for various salesforce products and modules. If you a have a project related to it then get in touch with us as we are a reputed and experienced <a href=\"https:\/\/multisitelocal.ezxdemo.com\/salesforce-consulting.html\">Salesforce consulting company<\/a>.<\/p>\n<h4>Also Read: <a href=\"https:\/\/multisitelocal.ezxdemo.com\/blog\/magento-commerce-vs-salesforce-commerce-cloud.html\" target=\"_blank\" rel=\"noopener\">Magento Commerce Cloud Vs Salesforce Commerce Cloud<\/a><\/h4>\n","protected":false},"excerpt":{"rendered":"<p>We have all tried to integrate different map APIs in salesforce, most popular being Google Map API. Although we have done a spectacular job while using it, how about using inbuilt functionality that Salesforce provides us with. Let us proceed with Lightning Map Component and how we can put it to our use. Lightning Map<\/p>\n","protected":false},"author":38,"featured_media":2226,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"MSN_Categories":"Uncategorized","MSN_Publish_Option":false,"MSN_Is_Local_News":false,"MSN_Is_AIAC_Included":"Empty","MSN_Location":"[]","MSN_Add_Feature_Img_On_Top_Of_Post":false,"MSN_Has_Custom_Author":false,"MSN_Custom_Author":"","MSN_Has_Custom_Canonical_Url":false,"MSN_Custom_Canonical_Url":"","_lmt_disableupdate":"","_lmt_disable":"","footnotes":""},"categories":[87],"tags":[],"class_list":{"0":"post-1894","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-salesforce-development"},"modified_by":"emizentech","featured_image_src":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-content\/uploads\/sites\/2\/2020\/04\/create-salesforce-lightning-map-component-1.png","featured_image_src_square":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-content\/uploads\/sites\/2\/2020\/04\/create-salesforce-lightning-map-component-1.png","author_info":{"display_name":"Sapna Chandani","author_link":"https:\/\/multisitelocal.ezxdemo.com\/blog\/author\/sapna-chandani"},"_links":{"self":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts\/1894","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/comments?post=1894"}],"version-history":[{"count":0,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/posts\/1894\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/media\/2226"}],"wp:attachment":[{"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/media?parent=1894"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/categories?post=1894"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/multisitelocal.ezxdemo.com\/blog\/wp-json\/wp\/v2\/tags?post=1894"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}