I would like to show a map of a specific location on Record Pages Since I have two objects where I would like to display this map I would like to make my component aware of its context before defining the variables for the map
I wanted to use @ObjectApiName like in the doc but every time I do it I get an error, Object API name is not defined .. I do not know what I am doing wrong...
My code looks the following:
import { LightningElement, wire, api } from 'lwc';
import { getRecord, getFieldValue } from "lightning/uiRecordApi";
import Latitude__c from "@salesforce/schema/Selina_Location__c.Latitude__c";
import Longitude__c from "@salesforce/schema/Selina_Location__c.Longitude__c";
import Latitude__c2 from "@salesforce/schema/Trip__c.Latitude__c";
import Longitude__c2 from "@salesforce/schema/Trip__c.Longitude__c";
//import Name__c from "@salesforce/schema/Selina_Location__c.Name__c";
export default class MapLocation extends LightningElement {
@api recordId;
@api objectApiName;
recordData;
mapMarkers;
zoomLevel = 12;
@wire(getRecord, {
recordId: "$recordId",
fields: [Latitude__c, Longitude__c, Latitude__c2, Longitude__c2],
})
getLocationData(wireResult) {
const { error, data } = wireResult;
if (data) {
this.recordData = data
console.log('dataToCheck',this.recordData['fields'])
console.log('dataToCheck34',this.recordData['fields']['Longitude__c']['value'])
this.mapMarkers = [
{
location: {
Latitude: this.recordData['fields']['Latitude__c']['value'],
Longitude: this.recordData['fields']['Longitude__c']['value'],
},
title: 'Ramon'
},
];
}
if (error) {
console.log(objectApiName);
this.error = error;
}
}
}