Find latitude and longitude using distance

I want to find Latitude, for example

Point A = (18.5204303,73.8567437)
Point B = (x,73.8567437)
Distance =20KM(Kilometers)

I need to find the latitude (x) of point B, that is, 20 km from point A. The duration should be the same. Help me thanks in advance

+5
source share
3 answers

I found the answer to my question

var lat1 = 18.5204303;
    var lon1 = 73.8567437;
    var d = 20;   //Distance travelled
    var R = 6371;
    var brng = 0;
    var LatMax;
    brng = toRad(brng); 
    var lat1 = toRad(lat1), lon1 = toRad(lon1);
    var lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
                      Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) );

    var lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                             Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2));
        lon2 = (lon2+3*Math.PI) % (2*Math.PI) - Math.PI;  
    lat2= toDeg(lat2);
    lon2= toDeg(lon2);
    alert(lat2);
    alert(lon2);

function toRad(Value) {
    /** Converts numeric degrees to radians */
    return Value * Math.PI / 180;
}
 function toDeg(Value) {
   return Value * 180 / Math.PI;
}

Thank you all

+3
source

I am not sure if this should be an answer or comment. But since I can not write comments, I will write an answer.

This page is a great source for calculating distances. In this case, you are probably looking for a code to calculate a new position when moving along a rail line from a given position. Quote from the page:

lat/lon tc, d (lat1, lon1) ( !):

lat= lat1+d*cos(tc)
IF (abs(lat) > pi/2) "d too large. You can't go this far along this rhumb line!"
IF (abs(lat-lat1) < sqrt(TOL))
{
    q=cos(lat1)
}
ELSE 
{
    dphi=log(tan(lat/2+pi/4)/tan(lat1/2+pi/4))
    q= (lat-lat1)/dphi
}
dlon=-d*sin(tc)/q
lon=mod(lon1+dlon+pi,2*pi)-pi

- , . , , . , .

+1
+1

All Articles