$(document).ready(function(){
L.mapbox.accessToken = 'pk.eyJ1Ijoicm9oYW4wNzkzIiwiYSI6IjhFeGVzVzgifQ.MQBzoHJmjH19bXDW0b8nKQ';
map = L.mapbox.map('map', 'inclanfunk.l4mg4b99').setView([39.72, -101.68], 5);
var coord1 = [39.72, -101.68];
var latLng1 = L.latLng(coord1[0], coord1[1]);
map.setView(coord1, 15);
var marker = L.marker(coord1).addTo(map);
var coord2 = getCoordinate(coord1, 100);
var latLng2 = L.latLng(coord2[0], coord2[1]);
var marker2 = L.marker(coord2).addTo(map);
//check distance with leaflet
var distance = latLng1.distanceTo(latLng2);
console.info(distance);
console.info(coord1, coord2);
// Let us assume radius is 100. How do I plot another marker 100 units away?
// Do I convert the 100 units to latitude or longitude and then plot the difference?
// I also need to make the other marker draggable which is easy
// But only on the in a fixed path, which is something I am confused about
});
function getCoordinate(coord, radius){
var r = radius / 111300
, y0 = coord[0]
, x0 = coord[1]
, 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)
var newY = y0 + y1,
newX = x0 + x1;
return [newY, newX];
}
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.