So I’m trying to follow the “Develop an Account Geolocation App with Aura Components ” project tutorial but for a custom object, and I’ve run into a problem with implementing the Map Component and Controller.

For some reason, my map markers are not showing up in my Map Component, and i'm getting the error

‘Cannot read property 'length' of null’. 

my records are showing up in my list component, but they still aren’t showing up in my map, any idea on why? I'm pretty sure it has something to do with my for loop, but it looks fine to me.

Here is the Map Component and Controller, followed by the event:


<aura:component >
    <aura:handler event = "c:SitesLoaded" action = "{!c.onSitesLoaded}"/>
    <aura:attribute name="MapMarkers" type="Map[]"/>
    <lightning:card title="Site Map" iconName = "action:map">
        <lightning:map mapMarkers="{!v.mapMarkers}"/>


    onSitesLoaded : function(component, event, helper) 
        var mapMarkers = [];
        var sites = event.getParam( 'sites' );
        for ( var i = 0; i < sites.length; i++ )
           var site = sites[i];
            var marker ={
                     Latitude: site.Site_Location__latitude__s,
             Longitude: site.Site_Location__longitude__s
                'title': site.Name,
                 'description': 'testing',
               'icon': 'standard:location',


<aura:event type="APPLICATION">
    <aura:attribute name="sites" type="uwt_sites__c[]"/>

I’m also encountering an error with my latitude and longitude fields, where it says:

‘Site_Location__latitude__s is not defined’ . 

the Site_Location field is a geolocation field, to my knowledge this is how you correctly reference the individual latitude and longitude fields correct? This is populated on all of my records, so I don't know why it would be null.

  • Are you sure you're getting data with this line - var sites = event.getParam( 'sites' ); ? If you get data here (you can confirm by adding console.log after this line. Then rest of the code work smoothly. – Ysr Shk Sep 10 at 3:16
  • @YsrShk I know my List Component is getting data with a line just like this. so why would my event work on my list component but not my map component? – Apex_rookie Sep 10 at 15:24

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.