0

HTML

<template>
    <div class="slds-m-around_medium">
        <h1 class="slds-text-heading_small">Single Marker</h1>
    </div>
    <lightning-map map-markers={mapMarkers}></lightning-map>
</template>

JS

import {
    LightningElement,
    api,
    wire,
    track
} from 'lwc';

import getLocation from '@salesforce/apex/LocationOnMapController.getLocation';

export default class LwcLocationOnMap extends LightningElement {

    @api recordId;
    @track error
    @track account = {};
    @track mapMarkers;

    @wire(getLocation, {
        accId: '$recordId'
    })
    wiredAccount({
        error,
        data
    }) {
        if (data) {
            this.account = data;
            console.log('data>>' + JSON.stringify(this.account));
            this.mapMarkers = [{
                location: {
                    Street: this.account.BillingStreet,
                    City: this.account.BillingCity,
                    State: this.account.BillingState,
                    Country: this.account.BillingCountry
                },
                Title: this.account.Name,
                description: this.account.Name + ' billing address',
                icon: 'standard:account'
            }, ];
            this.error = undefined;
        } else if (error) {
            this.error = error;
            this.account = undefined;
            console.log('ERROR : ' + this.error);
        }
    }
}

Apex

public with sharing class LocationOnMapController {
    
    @AuraEnabled(cacheable=true)
    public static Account getLocation( String accId){
        return [SELECT Id, Name, BillingStreet, BillingCity, BillingState, BillingPostalCode, BillingCountry 
        FROM Account 
        WHERE Id = :accId];
    }
}
2

The initial render is failing, resulting in the error you see. Try:

<lightning-map if:true={mapMarkers} map-markers={mapMarkers}></lightning-map>
| improve this answer | |

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.