B4A Class [B4X] GPSPolyMap - check if GPS location is inside a polygon

With this class, you can check if the GPS location coordinate is inside a polygon.
You can use this class to check whether the user is inside a building, shopping mall or any custom shape.
This class is only for B4A and B4I.

Here is how can you get the coordinates of an establishment (school, office, shopping mall or your own house):
  1. Open google map.
  2. Search for the establishment in which you want to track
  3. Start from a point/corner. Click on the starting point /corner.
  4. You will see a gray point and at the bottom, you will see a white box containing a coordinate.
  5. Add those points like below. And at last, add the starting point to close the polygon.
  6. Remember to add the points in the correct order so that none of the sides overlap with each other.

B4A/B4I Usage:
B4X:
Private PolyPoints As List
PolyPoints.initialize
PolyPoints.Add(CreateMap("lat":22.573515, "lng":88.371020))
PolyPoints.Add(CreateMap("lat":22.569855, "lng":88.370321))
PolyPoints.Add(CreateMap("lat":22.568923, "lng":88.375217))
PolyPoints.Add(CreateMap("lat":22.570707, "lng":88.373158))
PolyPoints.Add(CreateMap("lat":22.571181, "lng":88.376235))
PolyPoints.Add(CreateMap("lat":22.573515, "lng":88.375136))
PolyPoints.Add(CreateMap("lat":22.573515, "lng":88.371020)) 'add the first point at last to close the polygon

Private gpm as GPSPolyMap
gpm.Initialize(PolyPoints)


Sub GPS1_LocationChanged (Location1 As Location)
    Log(gpm.isInside(Location1.Latitude,Location1.Longitude,True))
End Sub
 

Attachments

  • GPSPolyMap.bas
    3.1 KB · Views: 606

TILogistic

Expert
Licensed User
Longtime User
How to check if the GPS is on a plotted route?

I ask this before posting the query on the forum.
 

Biswajit

Active Member
Licensed User
Longtime User
How to check if the GPS is on a plotted route?

I ask this before posting the query on the forum.
This is based on google.maps.geometry.poly.containsLocation. To check if the point is on the edge of a polyline you have to use google.maps.geometry.poly.isLocationOnEdge. I will try to post a class based on this soon.
 

TILogistic

Expert
Licensed User
Longtime User
Thank you,

In the meantime, we are going to translate to b4X what we have about route geometry calculations. (NOT google api of maps)

Regards,
 

TILogistic

Expert
Licensed User
Longtime User
info: year 2015

 

Biswajit

Active Member
Licensed User
Longtime User
info: year 2015

I think this will be more accurate as this is the exact same code that you will find in google map native sdk and javascript api. I use this in many app to restrict usage in a single city / state. Even this algorithm works in PHP.
 

TILogistic

Expert
Licensed User
Longtime User
Sorry,

My question was related to when there is zone A in B or A and B within C.
In which zone did I enter or exit?

or

when there are zones linked to A and B

Your solution is for one area only.

But okay, my congratulations.

Regards,
 

Biswajit

Active Member
Licensed User
Longtime User
Sorry,

My question was related to when there is zone A in B or A and B within C.
In which zone did I enter or exit?

or

when there are zones linked to A and B

Your solution is for one area only.

But okay, my congratulations.

Regards,
If there are multiple zone then create a new instance for each zone. And check if the GPS coordinate is inside of those or not.
 

TILogistic

Expert
Licensed User
Longtime User
yes,

but I would have to check each zone.

and not in a set of zones

simple example.

If zone A is inside B?

You would have to check together A and B, and not each individual zone.

is what is discussed in post # 6 I sent you.

as if in the center of the area

but this is a topic for a post

Thank you,

regards
 
Top