java – How to create a non-circular geofence area?

Question:

From what I saw, geofence creates a circular area from the radius measurement, in this case it creates a circular area, but is it possible to create a non-circular area?

For example a square or an abstract shape (polygon).

In my case, I wanted to create areas the size of neighborhoods in a particular city, if they know of some other way to do it, it's also valid

Answer:

With the shape of a generic polygon do not know.

If the shape of a rectangle is enough use the LatLngBounds class

To use, build a LatLngBounds informing the LatLng of the lower left corner (southWest) and the LatLng of the upper right corner (norhtEast)

LatLngBounds bounds = new LatLngBounds(southWest,norhtEast);

To check if a particular LatLng is inside the rectangle use:

boolean contains = bounds.contains(point); 
Scroll to Top