[英]Using Javascript, how can I randomly offset for Longitude and Latitude numbers
I have an array of Longitude/Latitude numbers that I loop through to spit out markers for a Google Map. 我有一组经度/纬度数字,可以循环使用这些数据以吐出Google Map的标记。 The markers I am using are circles to show a small area.
我使用的标记是圆圈,显示的区域很小。 I am trying to "slightly" privatize the locations by offsetting the numbers by a small amount.
我试图通过将数字偏移少量来“略微”私有化位置。 I am thinking fluctuations of +/- 0.001 to 0.009.
我认为波动范围为+/- 0.001至0.009。
An example is: lat: 47.6204674, lng -122.3491156. 一个示例是:lat:47.6204674,ng -122.3491156。
My current loop: 我当前的循环:
$.each(locations, function(i, item) {
// init markers
var marker = new google.maps.Marker({
position: new google.maps.LatLng(item.lat, item.lng),
map: map,
icon: circleIcon
});
});
I need to modify item.lat and item.lng 我需要修改item.lat和item.lng
thanks 谢谢
Adding in a random number in the range you suggest would work OK, 在您建议的范围内添加一个随机数就可以了,
position: new google.maps.LatLng(
item.lat + ((Math.random() > 0.5 ? 0.001 : -0.009) + Math.random() * 0.008),
item.lng ...),
But for added anonymity, you might want to seed the random number generator based on the user ID. 但是,为了增加匿名性,您可能希望根据用户ID为随机数生成器添加种子。 Otherwise some hacker could invoke your code N times, take the average, and accurately work out the position.
否则,某些黑客可能会N次调用您的代码,取平均值,然后准确得出结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.