You need to sign in to do that
Don't have an account?
pq100
Custom function to calculate straight line distance
Hi
I have a VB app that i'm migrating to Force.com, in this app i created a custom function to calculate the straight line distance bewteen 2 points (specified using British national Grid coordinates):
Function StraightLineDist(x1 As Double, y1 As Double, x2 As Double, y2 As Double) As Double xDiff = x1 - x2 yDiff = y1 - y2 xSqrt = xDiff * xDiff ySqrt = yDiff * yDiff StraightLineDist = Sqr(xSqrt + ySqrt) / 1000 End Function
using this i could take a point that a user had added and then query a seperate object to pull out, for example, all points within 5km.
Does anyone know if its possible to achieve somethign similar with Apex, if so i'd appreciate any pointers you can give me!
Thanks
Paul
yes, it's poaaible.....(may be something simillar)...
public void StraingLineDistance(double x1,double x2,double y1,double y2)
{
Double xdiff=x1-x2;
Double ydiff=y1-y2;
Double xsqrt = sqrt(xdiff);
Double ysqrt = sqrt(ydiff);
StraingLineDistance = sqrt(xsqrt +ysqrt ) / 1000;
}