If you're looking for a radius/distance calculation:
B4X:
Private Sub deg2rad(deg As Double) As Double
Return (deg * cPI / 180.0)
End Sub
Private Sub rad2deg(rad As Double) As Double
Return rad / cPI * 180.0
End Sub
Public Sub distance(lat1 As Double, lon1 As Double, lat2 As Double, lon2 As Double, unit As Char) As Double
If lat1 = lat2 And lon1 = lon2 Then
Return 0
Else
Dim theta As Double = lon1 - lon2
Dim dist As Double = Sin(deg2rad(lat1)) * Sin(deg2rad(lat2)) + Cos(deg2rad(lat1)) * Cos(deg2rad(lat2)) * Cos(deg2rad(theta))
dist = ACos(dist)
dist = rad2deg(dist)
dist = dist * 60 * 1.1515
If unit = "K" Then
dist = dist * 1.609344
Else If unit = "N" Then
dist = dist * 0.8684
End If
Return dist
End If
End Sub
I did a couple of calculations:
B4X:
Log( distance(35.8209082, -90.8088206, 35.1288636, -90.2509744, "M")) 'Jonesboro AR to Memphis TN : 57 miles
Log( distance(35.8209082, -90.8088206, 37.7048359, 14.9922625, "M")) 'Jonesboro AR to Zafferana : 5488 miles
You could add only the ones that are <80 miles. I will not be going to Zafferana since it is not <80 miles..
Here is a bit of a different approach. Works with triangles, squares, pentagons, hexagons, etc.. It will only work with convex shapes.
B4X:
Type Point (X As Double, Y As Double)
B4X:
Public Sub IsPointInPolygon(p As Point, pList() As Point) As Boolean
Dim minX As Double = pList(0).X
Dim maxX As Double = pList(0).X
Dim minY As Double = pList(0).Y
Dim maxY As Double = pList(0).Y
For b=1 To pList.length - 1
Dim q As Point = pList(b)
minX = Min(q.X, minX)
maxX = Max(q.X, maxX)
minY = Min(q.Y, minY)
maxY = Max(q.Y, maxY)
Next
If p.X < minX Or p.X > maxX Or p.Y < minY Or p.Y > maxY Then
Return False
End If
Dim inside As Boolean = False
Dim i As Int = 0
Dim j As Int = pList.length - 1
Do While i < pList.length - 1
Dim iPoint As Point = pList(i)
Dim jPoint As Point = pList(j)
If ((iPoint.Y > p.Y) <> (jPoint.Y > p.Y) And p.X < (jPoint.X - iPoint.X) * (p.Y - iPoint.Y) / (jPoint.Y - iPoint.Y) + iPoint.X) Then
inside = (inside = False)
End If
i = i + 1
j = Min(i, i - 1)
Loop
Return inside
End Sub
B4X:
Log("IS INSIDE: " & IsPointInPolygon(getPoint(25,1), Array As Point(getPoint(25, 0),getPoint(50,50),getPoint(0,50))))
Not sure if this would work with lat/lon points lol
I found that function on Google and just translated/tested it
I had to work on a couple of property/reality apps, and they stored the Lat,Lon of the properties, and showed them only if the distance is within the search threshold.
I'm not sure if there's anything in the API to do this though. I might research it
Computes whether the given point lies inside the specified polygon. The polygon is always considered closed, regardless of whether the last point equals the first or not. Inside is defined as not containing the South Pole -- the South Pole is always outside. The polygon is formed of great circle segments if geodesic is true, and of rhumb (loxodromic) segments otherwise.
I found that function on Google and just translated/tested it
I had to work on a couple of property/reality apps, and they stored the Lat,Lon of the properties, and showed them only if the distance is within the search threshold.
I'm not sure if there's anything in the API to do this though. I might research it