If i am not misunderstood, you are trying to find selected point (lat, lon) is in area of 4 other point (lat,lon) sort of like this case;
Ax,Ay Bx,By
A(10,20) B(20,20)
+-----------------+
| Px,Py |
| (15,15) |
| P |
| |
| |
+-----------------+
Cx,Cy Dx,Dy
C(10,10) D(20,10)
you can find this information matematically
A, B, C, D is the corner points of rectangle and P is a single point what you looking for.
Here is the code piece which can help you to find P is in square or not.
PS: Code is not written in editor, so it may contain typo or error. Please check carefully.
function isInsideSquare($Ax, $Ay, $Bx, $By, $Cx, $Cy, $Px, $Py) {
if (triangleArea($Ax,$Ay,$Bx,$By,$Px,$Py)>0 || triangleArea($Bx,$By,$Cx,$Cy,$Px,$Py)>0 || triangleArea($Cx,$Cy,$Dx,$Dy,$Px,$Py)>0 || triangleArea($Dx,$Dy,$Ax,$Ay,$Px,$Py)>0) {
return false;
}
return true;
}
function triangleArea($Ax, $Ay, $Bx, $By, $Cx, $Cy){
return ($Cx*$By-$Bx*$Cy)-($Cx*$Ay-$Ax*$Cy)+($Bx*$Ay-$Ax*$By);
}