Skip to content

Instantly share code, notes, and snippets.

@gee1k
Created January 13, 2021 04:03
Show Gist options
  • Save gee1k/41d3878f980816bb0ac0452319c1d39c to your computer and use it in GitHub Desktop.
Save gee1k/41d3878f980816bb0ac0452319c1d39c to your computer and use it in GitHub Desktop.
function distance(latlng1, latlng2) {
var rad = Math.PI / 180,
lat1 = latlng1.lat * rad,
lat2 = latlng2.lat * rad,
a = Math.sin(lat1) * Math.sin(lat2) +
Math.cos(lat1) * Math.cos(lat2) * Math.cos((latlng2.lng - latlng1.lng) * rad);
// 地球半径
return 6371000 * Math.acos(Math.min(a, 1));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment