我有一个经度/纬度数字数组,我循环这些数字以生成 Google map 的标记。我使用的标记是圆圈来显示一个小区域。我试图通过少量抵消数字来“稍微”私有(private)化这些位置。我在考虑 +/- 0.001 到 0.009 的波动。
例如:lat: 47.6204674, lng -122.3491156。
我当前的循环:
$.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
});
});
我需要修改 item.lat 和 item.lng
谢谢
最佳答案
在您建议的范围内添加一个随机数就可以了,
position: new google.maps.LatLng(
item.lat + ((Math.random() > 0.5 ? 0.001 : -0.009) + Math.random() * 0.008),
item.lng ...),
但为了增加匿名性,您可能希望根据用户 ID 为随机数生成器提供种子。否则某些黑客可能会调用您的代码 N 次,取平均值并准确计算出位置。
关于javascript - 使用 Javascript,我如何随机偏移经度和纬度数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23023259/