Skip to content

Instantly share code, notes, and snippets.

@tomek-f
Last active February 12, 2016 20:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomek-f/1552d52639ad6bbe829d to your computer and use it in GitHub Desktop.
Save tomek-f/1552d52639ad6bbe829d to your computer and use it in GitHub Desktop.
var eartMeanRadiusInMeters = 6378137;
function rad(x) {
return x * Math.PI / 180;
}
function distHaversine(p1, p2) {
var radLat = rad(p2.lat() - p1.lat());
var radLng = rad(p2.lng() - p1.lng());
var intermediate =
Math.sin(radLat / 2) * Math.sin(radLat / 2) +
Math.cos(rad(p1.lat())) * Math.cos(rad(p2.lat())) * Math.sin(radLng / 2) * Math.sin(radLng / 2);
return eartMeanRadiusInMeters * 2 * Math.atan2(Math.sqrt(intermediate), Math.sqrt(1 - intermediate));
}
// function getRadius() {
// var currentBounds = map.getBounds(),
// southWestOld = currentBounds.getSouthWest(),
// northEastOld = currentBounds.getNorthEast(),
// point1 = new google.maps.LatLng(northEastOld.lat(), southWestOld.lng()),
// point2 = southWestOld;
// return Math.ceil(distHaversine(point1, point2) / 2);
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment