Android Question Parse KML Polygones, Save, check if inside?

mw71

Active Member
Licensed User
Longtime User
Hello

I want to parse a KML file with polygons (XML2MAP ?) and save it (in a SQL file, or is there a more suitable way?)

Then the user should be able to check if he is within the boundaries of one of these polygons (areas).
The position of the user is provided by the GPS.

Is this possible?
 

josejad

Expert
Licensed User
Longtime User
Do you need this or do you need something different?

 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
Hi,

José, thank you, but unfortunately not.
"Geofence regions are defined as a circle with a center point and radius"
My areas are polygons, like this example http://dagik.org/kml_intro/E/polygon.html, but more Points, 2D....

the idea is to have a list of polygons and check if the (GPS) position is inside one of these polygons.
 
Upvote 0

roumei

Active Member
Licensed User
I use this code to check whether a point is inside a polyon:
B4X:
Type ePoint(X As Double, Y As Double)

Public Sub IsPointInPolygon(polygon() As ePoint, X As Double, Y As Double) As Boolean
    Dim result As Boolean = False
    Dim j As Int = polygon.length - 1
    For i = 0 To polygon.length - 1
        If polygon(i).Y < Y And polygon(j).Y >= Y Or polygon(j).Y < Y And polygon(i).Y >= Y Then
            If polygon(i).X + (Y - polygon(i).Y) / (polygon(j).Y - polygon(i).Y) * (polygon(j).X - polygon(i).X) < X Then
                result = Not(result)
            End If
        End If
        j = i
    Next
    Return result
End Sub
Taken from here: c# - Is point inside polygon? - Stack Overflow

You'll have to check whether it works with lat/lon values. I use projected coordinates in UTM or other coordinate systems.
 
Upvote 0
Top