Check user location (Geolocation ) is between geofence coordinates - Java / Spring / Backend

244 views Asked by At

I'm stuck with one scenario, We have geofence coordinates created by client/user, and also have user's current location. So want to check that, whether user is belong to that geofence area(coordinates) or not? We need to check it from backend/server side - Java is there.

Below are the GeoFence coordinates that may stored in our DB:

"42.43588461182335, -71.6158054921875",

"42.448988452992175, -71.61402648035278",

"42.44936844757593, -71.5879339510559",

"42.43299861648753, -71.59088339349671"

User's current location/coordinates which will sent by device to the backend:

42.440593799089996,-71.60585993854373


There are APIs available like (google map client for java) but they are related to Android and other mobile platform specific, not purely Java/backend specific. I want to compare these from server end.

So want some clue or any API that could be helpful to achieve the scenario.

any help would be appreciated, Thank you in Advance..! Have a Good Day.!

1

There are 1 answers

0
Rick James On

If the "backend DB" is MySQL, use PolygonFromText('POLYGON((...))') to define the fence if it is a polygon. There are other functions for other shapes.

Then use any of a few functions to see if a POINT is in the "Geometry".

https://dev.mysql.com/doc/refman/5.6/en/spatial-types.html

You will probably need a SPATIAL index to provide performance.