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
Sandeep Jadhav 17Sandeep Jadhav 17 

LWC #7 - Build the component boatsNearMe and display boats near you

I am getting below error.. seems html or java script issue with my script.

Challenge Not yet complete... here's what's wrong:
We can't find the right settings in the component boatsNearMe. Make sure the component was created according to the requirements, including the template tag that renders the spinner if isLoading is true.

Any thoughts ?
Maharajan CMaharajan C
Hi Sandeep,

Please compare the below code:

Check you have refered the loading spinner properly in component and createMapMarkers JS method.

Component:
 
<template>
    <lightning-card class="slds-is-relative">
       <!-- The template and lightning-spinner goes here -->
       <template if:true={isLoading}>
         <lightning-spinner variant="brand" alternative-text="Loading"></lightning-spinner>
       </template>
       <!-- The lightning-map goes here -->
       <template if:false={isLoading}>
         <lightning-map map-markers={mapMarkers}></lightning-map>
       </template>
       <div slot="footer">Top 10 Only!</div>
    </lightning-card>
 </template>

JS:
 
import { LightningElement,api,wire,track} from 'lwc';
import getBoatsByLocation from '@salesforce/apex/BoatDataService.getBoatsByLocation';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';

// imports
const LABEL_YOU_ARE_HERE = 'You are here!';
const ICON_STANDARD_USER = 'standard:user';
const ERROR_TITLE = 'Error loading Boats Near Me';
const ERROR_VARIANT = 'error';
export default class BoatsNearMe extends LightningElement {
  @api boatTypeId;
  @track mapMarkers = [];
  isLoading = true;
  isRendered = false;
  latitude;
  longitude;
  error
  
  // Add the wired method from the Apex Class
  // Name it getBoatsByLocation, and use latitude, longitude and boatTypeId
  // Handle the result and calls createMapMarkers
  @wire(getBoatsByLocation, { latitude: '$latitude', longitude: '$longitude', boatTypeId : '$boatTypeId' })
  wiredBoatsJSON({error, data}) { 
    if(data){
      this.error = undefined;
      this.createMapMarkers(JSON.parse(data));
      this.isLoading = false;
    }
    else if(error){
      this.mapMarkers = [];
      this.error = error;
      this.dispatchEvent(
        new ShowToastEvent({
            title: ERROR_TITLE,
            message: error,
            variant: ERROR_VARIANT
        })
      );
    }
  }
  
  // Controls the isRendered property
  // Calls getLocationFromBrowser()
  renderedCallback() { 
    if(!this.isRendered)
    {
      this.getLocationFromBrowser();
      this.isRendered = true;
    }
  }
  
  // Gets the location from the Browser
  // position => {latitude and longitude}
  getLocationFromBrowser() {
    if (navigator.geolocation) {
      navigator.geolocation.getCurrentPosition((position) => {
      this.latitude = position.coords.latitude;
      this.longitude = position.coords.longitude;
      console.log( 'lat => ' + this.latitude + ' :: ' + 'long => ' + this.longitude );
      });
    }
  }
  
  // Creates the map markers
  createMapMarkers(boatData) {
  const newMarkers = boatData.map(boat =>
        ({ 
            location: {
              Latitude: boat.Geolocation__Latitude__s,
              Longitude: boat.Geolocation__Longitude__s
            },
            title: boat.Name
          })
    );
    
  newMarkers.unshift({ 
    location: {
      Latitude: this.latitude,
      Longitude: this.longitude
    },
    title: LABEL_YOU_ARE_HERE,
    icon : ICON_STANDARD_USER
    }); 
  this.mapMarkers = newMarkers;
  this.isLoading = false;
  console.log('mapMarkers ==> '  + JSON.stringify( this.mapMarkers)); 
  }
}

Thanks,
Maharajan.C
AbhishekAbhishek (Salesforce Developers) 
Hi,

For all the Trailhead issues or Guidance please report it here,

https://trailhead.salesforce.com/en/help?support=home

https://trailhead.salesforce.com/help

So that our trailhead support engineers will look into it and get back to you.

Kindly let me know if it helps you and close your query by marking it as solved so that it can help others in the future. It will help to keep this community clean.

Regards,
Salesforce Support.