How to convert latitude and longitude?

How to calculate from these numbers:

51.501690392607,-0.1263427734375

to latitude and longitude?

It should be

London, England 51 ° 32 'N 0 ° 5' W
+3
source share
4 answers

To convert 51.501690392607, first take the integer part for 51 degrees. Positive values ​​are north; negatives are southern.

Then take the fractional part: 0.501690392607

Multiply by 60: 60 * 0.501690392607 = 30.10142355642

Take the integer portion for 30 minutes.

Then take the fractional part: 0.10142355642

Multiply by 60: 6.0854133852

1 .

: 51 30 6 .

/ .

, - - .

, .

+2

:

// to decimal
decimal = degree + minutes/60 + seconds/3600;

// from decimal
degree = int(decimal)
remaining = decimal - degree
minutes = int(remaining*60)
remaining = remaining - minutes/60
seconds = remaining*3600
+2

, :

degrees = int(frac)
minutes = int((frac - degrees) * 60)

"" "S" "W" ( "N" "E" ), "if".

, Python...:

def translate(frac, islatitude):
    if islatitude: decorate = "NS"
    else: decorate = "EW"
    if frac < 0:
        dec = decorate[1]
        frac = abs(frac)
    else:
        dec = decorate[0]
    degrees = int(frac)
    minutes = int((frac - degrees) * 60)
    return "%d %d %s" % (degrees, minutes, dec)

, :

print translate(51.501690392607, True),
print translate(-0.126342773437, False)

51 30 N 0 7 W

The decoration (degrees and minutes) depends on the character set support of your output device - and 7 versus 5 minutes of arc for the W coordinate, apparently, are the correct result for the numbers you enter.

+1
source

Source: https://habr.com/ru/post/1742699/


All Articles