Я пытаюсь использовать формулу haversin, чтобы предотвратить обновление таблицы mysql. Я реализую приложение, основанное на краудсорсинге, где данные mac, route, lat, long
записываются устройствами passangers im bus и отправляются на сервер.
Моя таблица базы данных имеет MAC-адрес как UNIQUE KEY
. Поэтому, чтобы избежать того, что другой пассажир на той же шине хранит свои данные в таблице, я бы отфильтровал эти запросы, используя Haversin formula
, но я попробовал это с буксировочной точкой, которая находится примерно в 20 метрах друг от друга, но я получаю число 4803.800129810092
//calculate the distance between the request's sender and all other request in the ArrayList.
private double haversineDistance(LatLong x, LatLong y) {
final int R = 6371; // Radious of the earth
double xLat = x.getLatitude();
double xLon = x.getLongitude();
double yLat = y.getLongitude();
double yLon = y.getLongitude();
;
double latDistance = toRad(yLat - xLat);
double lonDistance = toRad(yLon - xLon);
double a = Math.sin(latDistance / 2) * Math.sin(latDistance / 2)
+ Math.cos(toRad(xLat)) * Math.cos(toRad(yLat))
* Math.sin(lonDistance / 2) * Math.sin(lonDistance / 2);
double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));
double distance = R * c;
System.out.println("The distance between two lat and long is:" + distance);
return distance;
}