0

I'm asking this question in a different way, another user let me know what I need to ask for, I'm basically looking to convert to "decimal degrees". The conversion of course must be accurate. I see javascript solutions out there like this javascript example. I need ruby. Maybe someone could write the javascript in Ruby and I can try that, if that's easy of course and if it's right that is?

Basically I have this in my DB.

<coordinates_east>6'01.4</coordinates_east>
<coordinates_north>45'05.5</coordinates_north>

I need a routine written in Ruby to convert these to decimal degrees for use with the google maps API, possible?

Community
  • 1
  • 1
Rupert
  • 41
  • 3
  • 2
    So you do have working code, but do not want to translate the (rather easy) mathematics into the language of your choice and expect us to do this? – ty812 Nov 21 '09 at 09:10
  • You got it, fair point, I'll try it myself. I'm not sure if that JS code works, I'll try. – Rupert Nov 21 '09 at 09:14
  • 1
    As a hint ... your data is not in the D°M"S' format. It is Degrees - Minutes (which may be decimal). You should be able to just divide the minutes-part with the appropriate maximum for minutes in a degree, and be fine. – ty812 Nov 21 '09 at 09:18
  • OK, thanks, the separator is the ' I take it, if I've understood you correctly the east is 6 degrees and 1.4 minutes. Making a little ruby program right now. how could i regex out the degrees and minutes. – Rupert Nov 21 '09 at 09:42
  • 1
    Don't. If you've got XML, use an XML Parser - this will save you much headaces and prevent many of the error sources you'll likely encounter. Split 6°1.4 at the ° character, and receive an array of degree and minute – ty812 Nov 21 '09 at 11:35

1 Answers1

1

you want like this? not understand your question well though.

puts "6'01.4".scan(/(\d+)'(\d+)\.(\d+)/).map{|x,y,z|x.to_f+y.to_f/60+z.to_f/3600}
6.01777777777778
puts "36'57.9".scan(/(\d+)'(\d+)\.(\d+)/).map{|x,y,z|x.to_f+y.to_f/60+z.to_f/3600}
36.9525
YOU
  • 120,166
  • 34
  • 186
  • 219
  • thanks but not right i think, those results don't get me to the french alps in google earth, I end up in Africa - not much snow there! still trying. – Rupert Nov 21 '09 at 09:58
  • @Rupert you were propably mixing up latitude with longitude. – mmln Oct 20 '14 at 12:47