You can use the Haversine formula to approximate the «great-circle» distance between points on the globe, to get, say, the distance between map locations expressed in latitude and longitude. 🗺
You can see it in use in this javascript around line 247, the meat of which is this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
...calcDistance:function(loc1,loc2){varrad=function(x){returnx*Math.PI/180;}varR=6371;// earth's mean radius in km
vardLat=rad(loc2.latitude-loc1.latitude);vardLong=rad(loc2.longitude-loc1.longitude);vara=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(rad(loc1.latitude))*Math.cos(rad(loc2.latitude))*Math.sin(dLong/2)*Math.sin(dLong/2);varc=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));vard=R*c;returnd.toFixed(3);},...