# Android QuestionParse KML Polygones, Save, check if inside?

#### mw71

##### Active Member
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?

#### Erel

Staff member
Yes, it is possible. Yes, you should use Xml2Map.

#### José J. Aguilar

##### Expert
Do you need this or do you need something different?

#### mw71

##### Active Member
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.

• José J. Aguilar

#### roumei

##### Active Member
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.

• Erel and José J. Aguilar

Replies
9
Views
2K
B4A Class [Moved] GPSPolyMap
Replies
0
Views
999
Replies
5
Views
593
Android Question polyline from kml to txt
Replies
5
Views
2K
Replies
147
Views
96K