Dawood Awan
Dawood Awan

Reputation: 7348

Can't calculate Latitude. using Formula

I need to calculate Longitude and Latitude based on an old Longitude and Latitude, with distance and direction from that point.

From this link: http://www.movable-type.co.uk/scripts/latlong.html

I got these Formulae:

newLatitude = Math.Asin(Math.Sin(oldLatitude) * Math.Cos(distanceTravelled / earthRadius) + Math.Cos(oldLatitude) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(currentDirection));

newLongitude = oldLongitude + Math.Atan2(Math.Sin(currentDirection) * Math.Sin(distanceTravelled / earthRadius) * Math.Cos(oldLatitude), Math.Cos(distanceTravelled / earthRadius) - Math.Sin(oldLatitude) * Math.Sin(oldLatitude));

I have Acceleration e.g. 0.1 m/sec2

time travelled: Calculated from current time - start time.

Then I calculate the Distance travelled:

 distanceTravelled = distanceTravelled/1000;

I also have movement of direction in degrees: e.g. 90 degree. (East)

But I am getting Error in new Latitude see-image:

enter image description here

Do I have to enter direction in Radian?

Distance in KM instead of meter?

Please help me get the right Latitude?

Upvotes: 1

Views: 135

Answers (1)

Dawood Awan
Dawood Awan

Reputation: 7348

I found at the solution. I was using degree and decimal of latitude and longitude in above formulae. We have to use Radians

so convert Latitude, Longitude and Direction to Radians:

    oldLatitude = Math.PI * oldLatitude / 180;
    oldLongitude = Math.PI * oldLongitude / 180;
    currentDirection = Math.PI * currentDirection / 180.0;

then convert new Longitude and latitude from Radians to Degree again

            newLatitude = 180 * newLatitude / Math.PI;
            newLongitude = 180 * newLongitude / Math.PI;

Upvotes: 1

Related Questions