The first hit for Google’s “distance support”: Calculate distance, alerts, and more between latitude / longitude points
JavaScript code works fine in Ruby:
lat1 = 0.9250245 # starting point latitude (in radians) lon1 = 0.0174532 # starting point longitude (in radians) brng = 1.67551 # bearing (in radians) d = 124.8 # distance to travel in km R = 6371.0 # earth 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
source share