Reputation: 41
I need to do this..
<coordinates_east>6'01.4</coordinates_east>
<coordinates_north>45'05.5</coordinates_north>
I need to convert to this google friendly format in Ruby!...please note that these are not the real converted numbers just an example of the format I think I need!
<coordinates_east>45.46998</coordinates_east>
<coordinates_north>6.90764</coordinates_north>
How?
Upvotes: 2
Views: 1965
Reputation: 39695
my coordinates were space separated ("deg min sec") and I wrote this little lambda to handle them:
@to_decimal = lambda do |str|
deg, min, sec = str.split(" ").map(&:to_f)
if deg >= 0
output = deg + (min / 60.0) + (sec / 3600.0)
elsif deg < #HARD EARNED KNOWLEDGE HERE
output = deg - (min / 60.0) - (sec / 3600.0)
end
raise "something is wrong" if output.abs > 180
output
end
Upvotes: 1
Reputation: 59927
your input coordinates seem to be in wrong notation. it should probably be
<coordinates_north>45°05.5'</coordinates_north>
<coordinates_east>6°01.4'</coordinates_east>
(degrees° arcminutes'), or
<coordinates_north>45°05'5"</coordinates_north>
<coordinates_east>6°01'4"</coordinates_east>
(degrees° arcminutes' arcseconds")
once you figured out the correct input notation, you can use Parsing latitude and longitude with Ruby for converting them to decimal degrees. if your input notation is degrees° arcminutes', you have to modify it slightly. also pay attention to negative coordinates.
if you only want to use it with google maps, you don't actually need to convert it, because google maps understands arcminutes/-seconds notation.
Upvotes: 2