2024 Sep 03 3:19 AM
I really need some help. I used the build in geolocation function that saves the longitude and latitude to variables, I dont understand how to use the georadius function to check if the user is within a certain radius of a set of coordinates.
All I want is that when a user is at a certain location (with a radius of my choosing) it triggers a pop up toast. I have tried so many things, so far I can check to see if the users location coordinates are the same as the location im trying to trigger the toast but I cannot set a certain radius, the user basically has to already be at the location instead of getting a pop up when they are say 40 meters away from the location. I have looked into so many option I cannot figure it out. Please help thank you.
2024 Sep 03 6:26 AM
There's a formula to determine this... I suppose as a last resort you can ask Chatgpt or Gemini to write it in Javascript for you and then use the custom Javascript flow function.
2024 Sep 03 8:26 AM
Here's a function we used in our developer challenge (thanks @eshrinivasan) to tell if something is nearby. You can modify it to return the actual distance.
function arePointsNearBy(currentLocation, venueLocation, km) {
var ky = 40000 / 360;
var kx = Math.cos(Math.PI * venueLocation.lat / 180.0) * ky;
var dx = Math.abs(venueLocation.lng - currentLocation.lng) * kx;
var dy = Math.abs(venueLocation.lat - currentLocation.lat) * ky;
return Math.sqrt(dx * dx + dy * dy) <= km;
}
I'm sure Shrini can help if you need something even more sophisticated.