function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Patrick KaiserPatrick Kaiser 

AccountLocator

Hello Community

I've tried to build the AccountLocator project from Trailhead. The trailhead checks are all passed, but it dose give me an error "Something has gone wrong. Cannot read property 'lat' of null." every time i open the app and no markers are shown.

If i change the line of code from a) to b) the marker gets placed and there are no errors, but i can't find a solution to reach the function of the AccountLocator. On the Leaflet github i've found an simular error but i can't replicate the given solution.

I', quit new to javascript so i really could need some help with this issue.

Best Regards,
Patrick

a)
L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
                helper.navigateToDetailsView(event.target.options.account.Id);
            });
b)
var test = [37.784173, -122.401557]
L.marker([test[0],test[1]]).addTo(map);
My current AccountMapController.js
({
    jsLoaded: function(component, event, helper) {
        
        setTimeout(function() {
            var map = L.map('map', {zoomControl: false})
            .setView([37.784173, -122.401557], 14);
            L.tileLayer(
                'https://server.arcgisonline.com/ArcGIS/rest/services/World_Street_Map/MapServer/tile/{z}/{y}/{x}',
                {
                    attribution: 'Tiles © Esri'
                }).addTo(map);
            component.set("v.map", map);
        });
    },
    
    accountsLoaded: function(component, event, helper) {
    
        // Add markers
        var map = component.get('v.map');
        var accounts = event.getParam('accounts');
        for (var i=0; i<accounts.length; i++) {
            var account = accounts[i];
            var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
            
            //var test = [37.784173, -122.401557]
            //L.marker([test[0],test[1]]).addTo(map);
            
            L.marker(latLng, {account: account}).addTo(map).on('click', function(event) {
                helper.navigateToDetailsView(event.target.options.account.Id);
            });

        }
    },
    
    accountSelected: function(component, event, helper) {
        // Center the map on the account selected in the list
        var map = component.get('v.map');
        var account = event.getParam("account");
        map.panTo([account.Location__Latitude__s, account.Location__Longitude__s]);
    }
    
})
Patrick KaiserPatrick Kaiser
Hey,

i found my mistake. You have to add your namespace before the Location_Latitude__s. I've changed the line a) to b) and it works. Maybe it helps if someone has the same problem. Or maybe someone can add a sentence into the project description to help others.

Greeting and Thanks,
Patrick

a)
var latLng = [account.Location__Latitude__s, account.Location__Longitude__s];
b)
var latLng = [account.pkaiser__Location__Latitude__s, account.pkaiser__Location__Longitude__s];


 
Joseph Daily 29Joseph Daily 29

Hey Patrick,

I'm sorry, but what do you mean by "add your namespace"? Are you referring to the domain name of your sandbox, or something similar? Thanks in advance!

-Joseph Daily