2
0

📝 Improve getLocation set variable snippet (#1213)

Added location error handling.

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit


- **Refactor**
	- Updated location retrieval functionality:
		- Renamed function for clarity.
		- Enhanced location information to include latitude and longitude.
		- Improved error handling for smoother user experience.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Baptiste Arnaud <baptiste.arnaud95@gmail.com>
This commit is contained in:
Jason
2024-02-08 01:40:24 -06:00
committed by GitHub
parent 2f6de8e22c
commit 5f2ed4bf81

View File

@ -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.