How to build a marker from another marker 100 meters in Mapbox Leaflet?
I am trying to plot a marker using a Leaflet and then another marker from the first one at 100 meters. Marker application is easy:
var marker = L.marker([0, 0]).addTo(map);
But now how do I build another marker 100 meters away from this? Is there a way to convert meters to long and lat and then plot it? Or is there already a better way that I don't know about?
+3
Rohan
source
to share
1 answer
I have forked your fiddle to show an example. He based on these answers:
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
+1
Jonatas Walker
source
to share