B4J Question Maps: Marker distance from a polygon


Active Member
Licensed User
Hello all,

is there a way to find out if a circle ( a point with a radius ) overlaps with any of the polygons in a KMZ/KML file?

many thanks.


Staff member
Licensed User
If it doesn't need to be 100% accurate then you can treat the circle as a square and test whether any of the four points is inside the polygon (assuming that the circle is small relatively to the polygon).

Upvote 0

William Lancee

Active Member
Licensed User
If it needs to be accurate or if you have more complicated shapes than a circle:
Create two bitmaps (BitmapCreator). Draw filled polygons on one. Draw filled circle or other shape on other.
For each pixel coordinate, check if there is a filled color in both bitmaps. It is surprisingly fast.
Upvote 0


Active Member
Licensed User
Here is the code to get 8 points around a particular position, if someone is looking for this code.

Get Circular Coordinates:
'Input >> Source Lat, Source Lon and Distance
'Output >> List with map of Lat and Lon
Sub GetPoints(lat As Double, lon As Double,  d As Double) As List
    Dim R As Double= 6378.1 'Radius of the Earth   
    Dim brng  As Double
    Dim returnlist As List
    For angle = 0 To 360 Step 45
        Dim latitude1, longitude1 As Double
        Dim latitude2, longitude2 As Double
        Dim lat2 As Double
        Dim long2 As Double

        latitude1 = lat * (cPI / 180.0)
        longitude1 = lon * (cPI / 180.0)
        brng = angle  * (cPI / 180.0)

        latitude2 = ASin(Sin(latitude1)*Cos(d/R) + Cos(latitude1)*Sin(d/R)*Cos(brng))
        longitude2 = longitude1 + ATan2(Sin(brng)*Sin(d/R)*Cos(latitude1),Cos(d/R)-Sin(latitude1)*Sin(latitude2))
        latitude2 = latitude2 * (180/cPI)
        longitude2 = longitude2 * (180/cPI)
        lat2 = Round2 (latitude2,6)
        long2 = Round2 (longitude2,6)
'        Log(lat2 & "," & long2)

    Return returnlist
End Sub
Upvote 0