Is there any API for computing a geoforum violation other than the Android API

I would like to calculate the difference in geofence and the calculation of the distance in the backend. This is my first experience using the Google APIs. All I find on the Internet is Android. Is there any API for regular computing.

0
source share
1 answer

You can implement it yourself, without using any frameworks, it is very simple ...

I suppose you want to check if you are in a circle geo object or not.

To do this, simply calculate the distance between the center of the circle and your location (longitude, latitude). If the distance is less than the radius of your circle, then you are in the geosonde, otherwise you are outside the geoforum.

Like this:

boolean checkInside(Circle circle, double longitude, double latitude) { return calculateDistance( circle.getLongitude(), circle.getLatitude(), longitude, latitude ) < circle.getRadius();} 

To calculate the distance between two points, you can use this:

 double calculateDistance( double longitude1, double latitude1, double longitude2, double latitude2) { double c = Math.sin(Math.toRadians(latitude1)) * Math.sin(Math.toRadians(latitude2)) + Math.cos(Math.toRadians(latitude1)) * Math.cos(Math.toRadians(latitude2)) * Math.cos(Math.toRadians(longitude2) - Math.toRadians(longitude1)); c = c > 0 ? Math.min(1, c) : Math.max(-1, c); return 3959 * 1.609 * 1000 * Math.acos(c); } 

This formula is called the Haversin formula. It takes into account the curvature of the land. Results are shown in meters.

I also described this on my blog:

+4
source

Source: https://habr.com/ru/post/1012327/


All Articles