[英]How can I get the approximate address if I have the latitude and longitude with Leaflet?
[英]how to approximate a latitude/longitude to show an approximate location on the map?
我有一个用户的确切经度/纬度坐标(通过GPS检索)。 但是为了保护隐私,我不想在网站上显示精确的坐标。 我想返回在250m至500m之间随机移动的经度/纬度。 我怎样才能做到这一点 ?
这应该做。
var latitude = longitude = 24;
// Add offset to the coordinates
latitude += getRandomLongitudeOffset(250, 500);
longitude += getRandomLongitudeOffset(250, 500, latitude);
/*
Calculate one meter in degrees
1 degree = ~111km
1km in degree = ~0.0089
1m in degree = ~0.0000089
*/
const COEF = 0.0000089;
/**
* Returns an offset for coordinates in range [min, max]
*/
function getRandomLatitudeOffset(min, max){
return getRandomInt(min, max) * COEF;
}
function getRandomLongitudeOffset(min, max, latitude){
return (getRandomInt(min, max) * COEF) / Math.cos(latitude * 0.018);
}
/**
* Returns a random integer between min (inclusive) and max (inclusive)
* Using Math.round() will give you a non-uniform distribution!
*/
function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min + 1)) + min;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.