0

A user draws a line on a map and wants to find some information in a specific distance of that line. I have A and B locations in "lat, lon" format and the user tells me the distance (the distance between A and A1) in "meter, kilometer,...". How can i calculate A1, A2, B1, B2 locations in "lat, lon" format? I'm using C# and CoordinateSharp for working with locations.

enter image description here

p.s: I've read this and it works on cartesian grid system but i couldn't adapt its code for my problem.

  • Why couldn't you adapt it? Because you need an exact solution for spherical geometry or because you could not convert the lat, lon to numbers in km? – Olivier Jacot-Descombes Mar 05 '20 at 12:31
  • @OlivierJacot-Descombes almost both of them, i can tolerate maximum 10 meters of error in my calculations and i don't know how to replace lat for Y and long for X, longitude numbers are different for each latitude, now somehow i think this formula might not work for geo locations :-? – Mohammad Ferdosi Mar 05 '20 at 12:50
  • If you need an exact solution then this is probably rather a question for math.stackexchange.com – Olivier Jacot-Descombes Mar 05 '20 at 12:58
  • Convert lat/lon to UTM (CoordinateSharp can already to this apparently), perform the calculations in UTM (it's using meters as units) and then convert back to lat/lon. – Ionut Ticus Mar 05 '20 at 16:53

1 Answers1

2

Having A and B coordinates, you can calculate bearing in both points (note bearings are distinct in general case).

With bearing Fi in point A you can calculate bearings Fi - 90 and Fi + 90, and find points A1 and A2 at needed distance at corresponding bearings.

The same for B1, B2

You can get formulas from Bearing and Destination point given distance and bearing from start point chapters at this page

Bearing

θ = atan2( sin Δλ ⋅ cos φ2 , cos φ1 ⋅ sin φ2 − sin φ1 ⋅ cos φ2 ⋅ cos Δλ )

where   φ1,λ1 is the start point, φ2,λ2 the end point 
(Δλ is the difference in longitude)

Destination

φ2 = asin( sin φ1 ⋅ cos δ + cos φ1 ⋅ sin δ ⋅ cos θ )
λ2 = λ1 + atan2( sin θ ⋅ sin δ ⋅ cos φ1, cos δ − sin φ1 ⋅ 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
MBo
  • 77,366
  • 5
  • 53
  • 86