Skip to content

Instantly share code, notes, and snippets.

@eric-romero
Created October 12, 2023 22:55
Show Gist options
  • Select an option

  • Save eric-romero/70c3bdf5d0c9b4eaffca8e626fa3b348 to your computer and use it in GitHub Desktop.

Select an option

Save eric-romero/70c3bdf5d0c9b4eaffca8e626fa3b348 to your computer and use it in GitHub Desktop.
Save geolocation to record
diff --git a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
index 5c58aa1..8fc23c6 100644
--- a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
+++ b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.html
@@ -27,20 +27,6 @@
<!-- input fields -->
<lightning-input-field field-name={nameField}></lightning-input-field>
-
- <!-- Disable the button if LocationService isn't available -->
- <div class="slds-align_absolute-center slds-var-m-top_medium" if:false={requestInProgress}>
- <lightning-button
- variant="brand"
- disabled={locationButtonDisabled}
- icon-name="utility:checkin"
- label={buttonText}
- title="Use your device's GPS and other location sensors to determine your current location"
- onclick={handleGetCurrentLocationClick}>
- </lightning-button>
- </div>
- <lightning-input-field field-name={locationField} data-name="location" value={currentLocation}></lightning-input-field>
-
<lightning-input-field field-name={phoneField}></lightning-input-field>
<lightning-input-field field-name={websiteField}></lightning-input-field>
<lightning-input-field field-name={industryField}></lightning-input-field>
diff --git a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.js b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.js
index 3827208..21d4b86 100644
--- a/force-app/main/default/lwc/editAccountRecord/editAccountRecord.js
+++ b/force-app/main/default/lwc/editAccountRecord/editAccountRecord.js
@@ -1,6 +1,5 @@
-import { LightningElement, api, wire, track } from "lwc";
+import { LightningElement, api, wire } from "lwc";
import { getRecord } from "lightning/uiRecordApi";
-import { getLocationService } from "lightning/mobileCapabilities";
import NAME_FIELD from "@salesforce/schema/Account.Name";
import PHONE_FIELD from "@salesforce/schema/Account.Phone";
@@ -8,21 +7,15 @@ import WEBSITE_FIELD from "@salesforce/schema/Account.Website";
import INDUSTRY_FIELD from "@salesforce/schema/Account.Industry";
import TYPE_FIELD from "@salesforce/schema/Account.Type";
-import LOCATION_FIELD from "@salesforce/schema/Account.Location__c";
-
export default class EditAccountRecord extends LightningElement {
@api recordId;
@api objectApiName;
- @track currentLocation;
-
nameField = NAME_FIELD;
phoneField = PHONE_FIELD;
websiteField = WEBSITE_FIELD;
industryField = INDUSTRY_FIELD;
typeField = TYPE_FIELD;
- locationField = LOCATION_FIELD;
- locationService;
@wire(getRecord, { recordId: "$recordId", fields: [NAME_FIELD] })
record;
@@ -48,52 +41,4 @@ export default class EditAccountRecord extends LightningElement {
// eslint-disable-next-line no-restricted-globals
history.back();
}
-
- // When the component is initialized, detect whether to enable the button
- connectedCallback() {
- this.locationService = getLocationService();
- }
-
- handleGetCurrentLocationClick() {
- if (this.locationService != null && this.locationService.isAvailable()) {
- this.errorMessage = null;
-
- // Configure options for location request
- const locationOptions = {
- enableHighAccuracy: true,
- };
-
- // Make the request to get the location
- this.locationService
- .getCurrentPosition(locationOptions)
- .then((result) => {
- this.currentLocation = result.coords;
- })
- .catch((error) => {
- switch (error.code) {
- case "LOCATION_SERVICE_DISABLED":
- this.errorMessage = "Location service on the device is disabled."; // Android only
- break;
- case "USER_DENIED_PERMISSION":
- this.errorMessage =
- "User denied permission to use location service on the device.";
- break;
- case "USER_DISABLED_PERMISSION":
- this.errorMessage =
- "Toggle permission to use location service on the device from Settings.";
- break;
- case "SERVICE_NOT_ENABLED":
- this.errorMessage =
- "Location service on the device is not enabled.";
- break;
- case "UNKNOWN_REASON":
- default:
- this.errorMessage = error.message;
- break;
- }
- });
- } else {
- this.errorMessage = "Nimbus location service is not available.";
- }
- }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment