Created
March 17, 2012 06:10
-
-
Save raedatoui/2055680 to your computer and use it in GitHub Desktop.
Converting GPS from mmmm ss to dddd for Google Maps API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## SAMPLE data 3603.7517 N 11212.6268 W | |
lat_sign = LAT_FROM_DATA > 0 ? 1:-1 | |
lat = LAT_FROM_DATA | |
lat = lat[0,lat.length-1] #strip N | |
arr = lat.split('.') | |
if arr[0].length == 4 | |
deg= arr[0][0,2].to_f | |
min = arr[0][2,4].to_f | |
seconds = arr[1].to_f | |
lat = (deg + min/60 + seconds/600000).to_f | |
#puts "xxmm.dddd = " +lat.to_s | |
end | |
out["lat"] = (lat.to_f*lat_sign).round(6) | |
lon_sign = LONG_FROM_DATA > 0 ? 1:-1 | |
lon = LONG_FROM_DATA | |
log = lon[0,lon.length-1] #strip W | |
arr = lon.split('.') | |
if arr[0].length == 5 | |
deg = arr[0][0,3].to_f | |
min = arr[0][3,5].to_f | |
seconds = arr[1].to_f | |
lon = (deg + min/60 + seconds/600000).to_f | |
end | |
out["long"] = (lon.to_f*lon_sign).round(6) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment