문제

Dummy question here. I'm developing an app that fetches location-aware info. I'm getting location coordinates in following manner: lat=+aaa.bb.cc.dd&lon=+aaa.bb.cc.dd&datum=wgs84

How do I convert those coordinates into standard latitude longitude with single dot. Now it looks as if client is requesting an ip address lookup.

도움이 되었습니까?

해결책

wgs84 = '123.12.34.56'
deg, minute, second, fraction = wgs84.split(/\./).map(&:to_i)      # Ruby 1.9
deg, minute, second, fraction = wgs84.split(/\./).map {|x| x.to_i} # Ruby 1.8
deg += minute / 60.0 + second / 3600.0 + fraction / 360000.0
puts deg    # => 123.20970370370371

Takes the string with the wgs84 coordinate in it, splits it on the periods, converts the results from text '34' to numeric 34, and then does the division necessary to convert the minutes, seconds, and fractions of seconds to floating point adjustments added to the latitude (or longitude).

다른 팁

Emboldened by @Myrddin's near-agreement that he made a small mistake, I'm posting an answer in a blatant attempt to gather rep.

I suspect that

123.12.34.56

should be interpreted as 123d12m34.56s and converted to decimal degrees like this:

123+12/60+34.56/3600
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top