Create coordinate based on distance and direction

So i have coordinate (A) with x longitude and y latitude. What i want is create new coordinate (B) where distance (meter) between both of coordinate and direction (0 - 360) based on user input. What formula to achieve that?

so far what i do is use this formula from answer1 and answer2

new_latitude  = latitude  + (dy / r_earth) * (180 / pi);
new_longitude = longitude + (dx / r_earth) * (180 / pi) / cos(latitude * pi/180);

but it just create new coordinate with one direction, what i want is direction can be changed.

Upvotes: 1

Views: 3348

Answers (1)

MBo
MBo

Reputation: 80325

You can use formula from this excellent site (section Destination point given distance and bearing from start point)

var φ2 = Math.asin( Math.sin(φ1)*Math.cos(d/R) +
                    Math.cos(φ1)*Math.sin(d/R)*Math.cos(brng) );
var λ2 = λ1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(φ1),
                         Math.cos(d/R)-Math.sin(φ1)*Math.sin(φ2));

where φ is latitude, λ is longitude, θ is the bearing (clockwise from north), δ is the angular distance d/R; d being the distance travelled, R the earth’s radius

Upvotes: 4

Related Questions