Vincenty formula
Base for SO questions
by ABBEYSOFT
HTML
<script type="text/javascript"
src="https://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry,drawing">
</script>
<div id="results"></div>
<div id="map_canvas"></div>
CSS
#map_canvas{
width: 450px;
height: 400px;
}
JavaScript
function drawCircle(point, radius, dir, addtoBounds) {
var extp = []; // best practice is to use [] rather then new Array(), both do the same thing.
if (dir == 1) {
for (var i = 0; i < 361; i++) {
//destVincenty function returns a object with lat, lon, and final bearing.
var destPoint = destVincenty(point.lat(), point.lng(), i, radius);
//add new point
extp.push(new google.maps.LatLng(destPoint.lat, destPoint.lon));
if (addtoBounds) bounds.extend(extp[extp.length - 1]);
}
}
else {
for (var i = 361; i > 0; i--) {
//destVincenty function returns a object with lat, lon, and final bearing.
var destPoint = destVincenty(point.lat(), point.lng(), i, radius);
//add new point
extp.push(new google.maps.LatLng(destPoint.lat, destPoint.lon));
if (addtoBounds) bounds.extend(extp[extp.length - 1]);
}
}
return extp;
}
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Vincenty Direct Solution of Geodesics on the Ellipsoid (c) Chris Veness 2005-2012 */
/* http://creativecommons.org/licenses/by/3.0/ */
/* from: Vincenty direct formula - T Vincenty, "Direct and Inverse Solutions of Geodesics on the */
/* Ellipsoid with application of nested equations", Survey Review, vol XXII no 176, 1975 */
/* http://www.ngs.noaa.gov/PUBS_LIB/inverse.pdf */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/**
* Calculates destination point given start point lat/long, bearing & distance,
* using Vincenty inverse formula for ellipsoids
*
* @param {Number} lat1, lon1: first point in decimal degrees
* @param {Number} brng: initial bearing in decimal degrees
* @param ...