如何在 Mapbox Leaflet 中将标记与另一个标记相距 100 米?
How to plot a marker away from another marker by 100 metres in Mapbox Leaflet?
我正在尝试使用 Leaflet 绘制一个标记,然后在距离第一个标记 100 米处绘制另一个标记。绘制标记很容易:
var marker = L.marker([0, 0]).addTo(map);
但是现在我如何绘制另一个标记,使其远离这个标记 100 米?
有没有办法将米转换为经度和纬度,然后绘制出来?
还是有我不知道的更好的方法?
我已经 forked your fiddle 举了一个例子。它基于以下答案:
https://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location
var r = 100/111300 // = 100 meters
, y0 = original_lat
, x0 = original_lng
, u = Math.random()
, v = Math.random()
, w = r * Math.sqrt(u)
, t = 2 * Math.PI * v
, x = w * Math.cos(t)
, y1 = w * Math.sin(t)
, x1 = x / Math.cos(y0)
newY = y0 + y1
newX = x0 + x1
我正在尝试使用 Leaflet 绘制一个标记,然后在距离第一个标记 100 米处绘制另一个标记。绘制标记很容易:
var marker = L.marker([0, 0]).addTo(map);
但是现在我如何绘制另一个标记,使其远离这个标记 100 米? 有没有办法将米转换为经度和纬度,然后绘制出来? 还是有我不知道的更好的方法?
我已经 forked your fiddle 举了一个例子。它基于以下答案:
https://gis.stackexchange.com/questions/25877/how-to-generate-random-locations-nearby-my-location
var r = 100/111300 // = 100 meters
, y0 = original_lat
, x0 = original_lng
, u = Math.random()
, v = Math.random()
, w = r * Math.sqrt(u)
, t = 2 * Math.PI * v
, x = w * Math.cos(t)
, y1 = w * Math.sin(t)
, x1 = x / Math.cos(y0)
newY = y0 + y1
newX = x0 + x1