Rails/ruby​​使用给定距离和从起点开始的方位计算新坐标

use*_*849 4 ruby geometry geolocation ruby-on-rails-3

在ruby/rails中有一个简单的非数学类和确定的方法,输入是:

1) An Initial Geo-Coordinate 
2) A Bearing
3) A Distance in the Bearing's Direction
Run Code Online (Sandbox Code Playgroud)

输出是一个新的 Geo-Coordinate

我看过Ruby Geocoder Gem,但它没有这样做.

谢谢!

Ste*_*fan 7

谷歌中的"距离承载"首次命中:计算纬度/经度点之间的距离,方位和更多

JavaScript代码在Ruby中运行得很好:

lat1 = 0.9250245 # starting point's latitude (in radians)
lon1 = 0.0174532 # starting point's longitude (in radians)
brng = 1.67551   # bearing (in radians)
d    = 124.8     # distance to travel in km
R    = 6371.0    # earth's radius in km

lat2 = Math.asin( Math.sin(lat1)*Math.cos(d/R) + 
          Math.cos(lat1)*Math.sin(d/R)*Math.cos(brng) )
# => 0.9227260710962849                  

lon2 = lon1 + Math.atan2(Math.sin(brng)*Math.sin(d/R)*Math.cos(lat1), 
                 Math.cos(d/R)-Math.sin(lat1)*Math.sin(lat2))
# => 0.0497295729068199      

# NB. Ensure that all values are cast to floats    
Run Code Online (Sandbox Code Playgroud)