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
Manish Anand 22Manish Anand 22 

Lightning component framework specialist superbadge step 10 : Issue in passing geolocation as an event parameters

Hi,
I am having issue in passing latitude and longitude as an event parameters. Below is my onBoatClick controller.
({
	onBoatClick : function(component, event, helper) {
        var BoatSelectEvent = component.getEvent("BoatSelect");
        var boatSelected = component.get("v.boat");
        BoatSelectEvent.setParam(
            "boatId",boatSelected.Id);
        BoatSelectEvent.fire();
        var BoatSelectedEvt = $A.get("e.c:BoatSelected");
        var Boat = component.get("v.boat");
        BoatSelectedEvt.setParams({
            "boat" : Boat
        }) ;
        console.log('Firing event' +Boat);
        BoatSelectedEvt.fire();
        
        var boat=component.get('v.boat');
        console.log('Boat Selected Id in boattile' + boat.Id);
        var lat = boat.Geolocation_Latitude__s;
        var long = boat.Geolocation_Longitude__s;
        var label = boat.Name;
        console.log('boat name in BoatTile'+ label);
        console.log('Latitude in BoatTile' + lat);
        console.log('Longitude in BoatTile' + long);
        var PlotMapMarkerEvent = $A.get("e.c:PlotMapMarker");
         PlotMapMarkerEvent.setParams({
            "lat"   : lat,
            "long"  : long,
            "label" : label,
             "SObjectId" : boat.Id });
         PlotMapMarkerEvent.fire();
        
		
	} ,

console.log display label and boat Id. However values for lat and lon is undefined. Not sure, what I am missing here.

Any help is appreciated. 

Thanks much.
Raj VakatiRaj Vakati
Use this code 

https://raw.githubusercontent.com/donaldrivard/Lightning_Component_Framework_Specialist/384cc06741a010adc88c6abedebe559df5436e89/deploy/aura/BoatTile/BoatTileController.js​
 
({
    onBoatClick : function(component, event, helper) {


        var boatSelectEvent = component.getEvent("BoatSelect");
        var selected = event.getSource().get("v.name");
        boatSelectEvent.setParams({ "boatId" : selected });
        boatSelectEvent.fire();      
        
        var boatSelectedEvent = $A.get("e.c:BoatSelected");
        var boat = component.get("v.boat")
        boatSelectedEvent.setParams({ "boat" : boat });
        boatSelectedEvent.fire();

        var lat = boat.Geolocation__Latitude__s;
        var long = boat.Geolocation__Longitude__s;
        var label = boat.Name;
        var sObjectId;
        console.log("Geo " + lat + " " + long + " " + label);
        
        var PlotMapMarker = $A.get("e.c:PlotMapMarker");
        PlotMapMarker.setParams({
            "lat"   : lat,
            "long"  : long,
            "label" : label,
            "SObjectId" : boat.Id
        });

        PlotMapMarker.fire();

    }
})

 
Manish Anand 22Manish Anand 22
lat and long values still showing as undefined in the console.log . Could you please check, if its showing for you?
 
siripurapu kavyasiripurapu kavya
Hi Manish, Make sure you are accessing the values Geolocation__Latitude__s and Geolocation__Longitude__s in SOQL query too in apex class. Also, since javascript is case sensitive make sure Geolocation__Latitude__s and Geolocation__Longitude__s are accessed correctly in controller bundle.
Andrew Frederick 5Andrew Frederick 5

I had a similar issue with the geolocation returning 'undefined'.

Like siripurapu said make sure you query for those fields. Also the OP missed the double underscore betweem 'Geolocation' and 'latitude' and 'longitude' so that would be a problem for them.

What really got me is according to salsforce documentation 'Geolocation__latitude__c' is correct and it is queried as such with no problem... BUT the returned values in the js controller of 'latitude' and 'longitude' are CAPITALIZED... and since js is case sensitive you have to reference them as such 'Geolocation__Latitude__c', etc...

Hope I save someone some time. Cheers!

Sharath JalluSharath Jallu
Please check if the Geolocation fields are queried or not in the apex controller "BoatSearchResults". 
This should solve mostly.