簡體   English   中英

使用Javascript,如何隨機偏移經度和緯度數字

[英]Using Javascript, how can I randomly offset for Longitude and Latitude numbers

我有一組經度/緯度數字,可以循環使用這些數據以吐出Google Map的標記。 我使用的標記是圓圈,顯示的區域很小。 我試圖通過將數字偏移少量來“略微”私有化位置。 我認為波動范圍為+/- 0.001至0.009。

一個示例是:lat:47.6204674,ng -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次調用您的代碼,取平均值,然后准確得出結果。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM