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

标签 ruby ruby-on-rails-3 geolocation geometry

在 ruby​​/rails 中是否有一种简单的、非数学类的和确定的方法来执行此操作,其中输入是:

1) An Initial Geo-Coordinate 
2) A Bearing
3) A Distance in the Bearing's Direction

输出是一个新的地理坐标

我看过 Ruby Geocoder Gem ,但它不会这样做。

谢谢!

最佳答案

在 Google 中首次搜索“距离方位”:Calculate distance, bearing and more between Latitude/Longitude points

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    

关于ruby - Rails/ruby 从起点使用给定距离和方位计算新坐标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12094484/

相关文章:

ruby-on-rails - ActiveRecord::Migration 类名中的方括号?

ruby - 如何在 ruby​​ 中打开安全连接

firebase - Flutter Firestore Geo 查询距我所在位置一定距离

java - JAVA中解析googleapi地址时出错

mysql - 无法使用 rails 连接到远程 mysql 数据库

ruby - 谷歌的 Omniauth 错误

mysql - 无法将日期格式从 Rails 形式转换为 mysql db

iOS 如何知道我正在穿越特定位置

ruby-on-rails - 如何从 Rails Controller 异步运行 ruby​​ 脚本?

ruby-on-rails-3 - 添加依赖项 :destroy in the Relationship model (Chapter 11, 练习 1 Rails 教程,第 2 版的测试)