How to convert degree minute second to degree decimal

后端 未结 6 2259
小鲜肉
小鲜肉 2021-02-07 13:37

I receive the latitude and longitude from GPS with this format:

Latitude : 78°55\'44.29458\"N

I need convert this data to:

latitude: 78.9288888889

<
6条回答
  •  梦谈多话
    2021-02-07 14:04

    I know this is an old question, but for whoever is following along, just thought I'd point out that you seem to have incorrect logic in your dms2dd() function regarding the sign of your decimals. You have:

    if direction == 'E' or direction == 'N':
        dd *= -1
    

    But it should only be negative if the direction is West (W) of the Prime Meridian or South (S) of the equator. So it should rather be:

    if direction == 'W' or direction == 'S':
        dd *= -1
    

    Here's a quote from a thorough guide: https://www.ubergizmo.com/how-to/read-gps-coordinates/

    The coordinate for the line of latitude represents north of the Equator because it is positive. If the number is negative, it represents south of the Equator.

    [...] The coordinate for the line of longitude represents east of the Prime Meridian because it is positive. If the number is negative, it represents west of the Prime Meridian.

提交回复
热议问题