# B4J QuestionMaps: Marker distance from a polygon

#### prajinpraveen

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

#### Erel

##### B4X founder
Staff member
Longtime 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).

• prajinpraveen

#### prajinpraveen

##### Active Member
Longtime User
That is a brilliant idea. I am going to put this to work. I will feedback on the result.

#### William Lancee

##### Well-Known Member
Longtime 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.

• prajinpraveen and Sandman

#### prajinpraveen

##### Active Member
Longtime User
Thank you. I will give this one a try too. The solution will be a Non-UI ( API calls )

#### prajinpraveen

##### Active Member
Longtime 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
returnlist.Initialize
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)
Next

Return returnlist
End Sub``````

• Mark Turney and gravel

Replies
1
Views
779
Replies
9
Views
3K
Replies
2
Views
374
Replies
8
Views
1K