SAP Builders Discussions
Join the discussion -- ask questions and discuss how you and fellow SAP Builders are using SAP Build, SAP Build Apps, SAP Build Process Automation, and SAP Build Work Zone.
cancel
Showing results for 
Search instead for 
Did you mean: 

Using location functions and variables

StacksIndeed
Explorer
0 Kudos
282

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.

2 REPLIES 2

srose99
Explorer
0 Kudos
208

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. 

Dan_Wroblewski
Developer Advocate
Developer Advocate
0 Kudos
156

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. 




--------------
See all my blogs and connect with me on Twitter / LinkedIn