Lat Long to Minutes and Seconds?

♀尐吖头ヾ 提交于 2019-11-27 07:44:19

问题


Google Maps gives me the Lat and Long of a location in decimal notation like this:

38.203655,-76.113281

How do I convert those to Coords (Degrees, Minutes , Seconds)


回答1:


38.203655 is a decimal value of degrees. There are 60 minutes is a degree and 60 seconds in a minute (1degree == 60min == 3600s).

So take the fractional part of the value, i.e. 0.203655, and multiply it with 60 to get minutes, i.e. 12.2193, which is 12 minutes, and then repeat for the fractional part of minutes, i.e. 0.2193 = 13.158000 seconds.

Example in python:

def deg_to_dms(deg):
    d = int(deg)
    md = abs(deg - d) * 60
    m = int(md)
    sd = (md - m) * 60
    return [d, m, sd]

print deg_to_dms(38.203655)
print deg_to_dms(-76.113281)



回答2:


In case you need other geo-related functionality in JavaScript, you may use the following library

http://www.movable-type.co.uk/scripts/latlong.html

it provides the following functionality:

  • DMS from/to decimal latitude/longitude conversions
  • Distance calculations
  • Bearing calculation
  • Intersection point calcualtion



回答3:


Python library that does the trick:

https://pypi.python.org/pypi/LatLon/1.0.2




回答4:


I think this will help you with the solution :

def deg_min_sec(self,degrees=0.0):
        if type(degrees) != 'float':
            try:
                degrees = float(degrees)
            except:
                print '\nERROR: Could not convert %s to float.' % (type(degrees))
                return 0
        minutes = degrees % 1.0 * 60
        seconds = minutes % 1.0 * 60

        return (degrees, minutes, seconds)


来源:https://stackoverflow.com/questions/2056750/lat-long-to-minutes-and-seconds

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!