简体   繁体   English

使用Javascript,如何随机偏移经度和纬度数字

[英]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.

相关问题 使用javascript查找纬度和经度 - Find the latitude and longitude using javascript 使用javascript获取经度和纬度 - get the latitude and longitude using javascript 如何将纬度和经度转换为北、南、东、西。 如果可能在 javascript 中? - How can I convert latitude & longitude into north,south,east,west. if its possible In javascript? 如何在 JavaScript 中使用纬度和经度从地图区域(多边形)偏移特定的长度单位? - how to offset specific unit of length from a map area(polygon) with latitude and longitude in JavaScript? 我如何选择经度和纬度以返回特定位置 javascript - how do i select the longitude and latitude to return specific locations javascript 如何使用JavaScript从经纬度获取位置名称? - How to get location name from latitude and longitude using javascript? 如何使用JavaScript代码找到我的真实经纬度? - How to find my real latitude and longitude using JavaScript code? 如何在 JavaScript 中使用经度和纬度获取地名 - How to get place name using longitude and latitude in JavaScript 如何使用javascript显示离我所在地点最近的纬度和经度? - How to display the nearest latitude and longitude to my location using javascript? 如何使用javascript根据一组纬度和经度值计算面积? - How to calculate an area based on the set of Latitude and longitude values using javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM