Parsing latitude and longitude with Ruby
问题 I need to parse some user submitted strings containing latitudes and longitudes, under Ruby. The result should be given in a double Example: 08º 04' 49'' 09º 13' 12'' Result: 8.080278 9.22 I've looked to both Geokit and GeoRuby but haven't found a solution. Any hint? 回答1: "08° 04' 49'' 09° 13' 12''".gsub(/(\d+)° (\d+)' (\d+)''/) do $1.to_f + $2.to_f/60 + $3.to_f/3600 end #=> "8.08027777777778 9.22" Edit: or to get the result as an array of floats: "08° 04' 49'' 09° 13' 12''".scan(/(\d+)° (\d+