Last active
February 12, 2016 20:27
-
-
Save tomek-f/1552d52639ad6bbe829d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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