Leaflet 1.1.0, MacOS
I have two LatLngs:
latLng1 = L.latLng({lat: 52.23217549533735, lng: 30.11111111111111})
latLng2 = L.latLng({lat: 52.23217549533735, lng: 30.11122222222222})
And I want to calculate distance between this two poins:
latLng1.distanceTo(latLng2)
And I receive different results on Chrome 61.0.3163.100
LatLng1.distanceTo(LatLng2) = 7.566885205402047
And on Firefox 55.0.3
LatLng1.distanceTo(LatLng2) = 7.567480718345588
It happens because L.latLng.distanceTo() method uses L.CRS.Earth.distance() method for calculations
distance: function (latlng1, latlng2) {
var rad = Math.PI / 180,
lat1 = latlng1.lat * rad,
lat2 = latlng2.lat * rad,
a = Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad);
return this.R * Math.acos(Math.min(a, 1));
}
and debugging step by step I realize that inside this function when calculating result
trigonometric functions sometimes has different values in Chrome and Firefox.
This is very small difference but it affects for the end result
Just ran a quick test in win10 with the same versions of Chrome and Firefox, seems results are the same across these browsers: both render an answer of 7.566885205402047. Not sure if this is a platform specific problem?
Might be related to #4675.
Voting to close: if browsers implement trig functions differently, it's not much Leaflet can do about it. In this particular case, this cause millimeter (or 0.008%) difference between browsers, well beyond any precision you can expect to use Leaflet for.
Voting to close as non-issue
Most helpful comment
Voting to close: if browsers implement trig functions differently, it's not much Leaflet can do about it. In this particular case, this cause millimeter (or 0.008%) difference between browsers, well beyond any precision you can expect to use Leaflet for.