Calculate Latitude and Longitude from Distance and Bearing

random

Calculate Latitude and Longitude from Distance and Bearing

Get point coordinates based on bearing and distance 

This JavaScript example demonstrates how to get new latitude and longitude from starting point A, bearing (Angle) and distance. Find the code snippet below:-
Bearing and Distance Calculator - Google Maps API
Find Coordinates With Distances and Angles
Utility.js
function ComputeLatLng(vLatitude, vLongitude, vAngle, vDistance) {
            var vNewLatLng = [];
            vDistance = vDistance / 6371;
            vAngle = ToRad(vAngle);

            var vLat1 = ToRad(vLatitude);
            var vLng1 = ToRad(vLongitude);

            var vNewLat = Math.asin(Math.sin(vLat1) * Math.cos(vDistance) +
                          Math.cos(vLat1) * Math.sin(vDistance) * Math.cos(vAngle));

            var vNewLng = vLng1 + Math.atan2(Math.sin(vAngle) * Math.sin(vDistance) * Math.cos(vLat1),
                                  Math.cos(vDistance) - Math.sin(vLat1) * Math.sin(vNewLat));

            if (isNaN(vNewLat) || isNaN(vNewLng)) {
                return null;
            }

            vNewLatLng[0] = ToDeg(vNewLat);
            vNewLatLng[1] = ToDeg(vNewLng);

            return vNewLatLng;
        }

        function ToRad(vInput) {
            return vInput * Math.PI / 180;
        }


        function ToDeg(vInput) {
            return vInput * 180 / Math.PI;
        }

Calculate Latitude and Longitude from Distance and Bearing Reviewed by Ravi Kumar on 10:21 PM Rating: 5

No comments:

All Rights Reserved by Etechpulse © 2012 - 2017

Contact Form

Name

Email *

Message *

Powered by Blogger.