I am new to PowerApps. I have a Share Point List with a set of coordinates for various locations. What I need to figure out is when a user with PowerApps App on their phone are within a certain distance of those coordinates, using the Haversine formula. While the Haversine formula works in a test/simple way using hard-coded target location, I need the target locations from the Share Point List. Here is my code, which is inside a Timer End:
ForAll(
irfan_yard_locations,
With(
{
r: 6371000, p: (Pi() / 180), latA: location_lat, lonA: location_long, latB: Location.Latitude, lonB: Location.Longitude
},
Round((2 * r) * Asin(Sqrt(0.5 - Cos((latA - latB) * p)/2 Cos(latB * p) * Cos(latA * p) * (1 - Cos((lonA - lonB) * p)) / 2)), 2 ));
) ;
irfan_yard_locations
is the SP List which has location_lat
and location_long
coordinates. I am thinking something like in this example site: http://powerappsguide.com/blog/post/formula-how-to-use-the-if-and-switch-functions so that if the return from the with ()
, which would be a number, is less than 5 (it's in meters) then Navigate to another screen or do something. Just don't know the syntax. Or is there better approach?
Thanks!
CodePudding user response:
Never mind. By putting in an If
clause around the With
function, I am able to catch if the current location is within 6 meters of one of the coordinate sets.
ForAll(
irfan_yard_locations,
If ( With(
{
r: 6371000, p: (Pi() / 180), latA: location_lat, lonA: location_long, latB: Location.Latitude, lonB: Location.Longitude
},
Round((2 * r) * Asin(Sqrt(0.5 - Cos((latA - latB) * p)/2 Cos(latB * p) * Cos(latA * p) * (1 - Cos((lonA - lonB) * p)) / 2)), 2 )) < 6, Navigate(Screen2));
) ;