diff --git a/apps/docs/editor/blocks/logic/set-variable.mdx b/apps/docs/editor/blocks/logic/set-variable.mdx index 4b43ae60f..4faac7199 100644 --- a/apps/docs/editor/blocks/logic/set-variable.mdx +++ b/apps/docs/editor/blocks/logic/set-variable.mdx @@ -127,17 +127,24 @@ This value block allows you to find the `Id` from `Ids` with the same index as ` For this you can provide the following custom code: ```js -function getPosition() { - return new Promise((resolve, reject) => { +function getLocation() { + return new Promise((resolve) => { navigator.geolocation.getCurrentPosition( - (position) => resolve(position), - (error) => reject(error), + position => resolve(`${position.coords.latitude}, ${position.coords.longitude}`), + error => resolve("error"), { enableHighAccuracy: true, timeout: 5000 } - ) - }) + ); + }); } -const coords = (await getPosition()).coords +const coords = await getLocation(); -return `${coords.latitude}, ${coords.longitude}` +// Check for error +if (coords === "error") { + return "Unable to get location"; +} + +return coords; ``` + +This custom function can only work when it is executed on the client browser so you need to make sure to enable the "Execute on client" option.