Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save phamquyhai/92d95154c45ddea6fe1902e8824a22fd to your computer and use it in GitHub Desktop.
Save phamquyhai/92d95154c45ddea6fe1902e8824a22fd to your computer and use it in GitHub Desktop.
Lat/Lon to Meters using Mercator projection
puts "Enter latitude in decimal degrees:"
lat_deg = gets.to_f
puts "Enter longitude in decimal degrees:"
lon_deg = gets.to_f
lon_rad = (lon_deg / 180.0 * Math::PI)
lat_rad = (lat_deg / 180.0 * Math::PI)
sm_a = 6378137.0
x = sm_a * lon_rad
y = sm_a * Math.log((Math.sin(lat_rad) + 1) / Math.cos(lat_rad))
puts "x: " + x.to_s + ", y: " + y.to_s
# More information: http://gis.stackexchange.com/questions/15269/how-to-convert-lat-long-to-meters-using-mercator-projection-in-c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment