I have saved HEIC photos taken by my iphone. I opened it and try find out the lat and lng numbers. What it shows is completely different to the format shown in google and it is not searchable. How do I convert these numbers to conform Google maps?
The numbers are as follows: Latitude: 39;53;0.6499999 Longitude: 116;9;24.4199999
You can use 're' (regular exploration) library to convert your string to "degrees, minutes, seconds"
Then convert those value into Decimal Degree format.
import re
def extract_lat_long(coord_string):
pattern = r'Latitude: (\d+;\d+;\d+\.\d+) Longitude: (\d+;\d+;\d+\.\d+)'
match = re.search(pattern, coord_string)
if match:
latitude_input_string = match.group(1)
longitude_input_string = match.group(2)
return latitude_input_string, longitude_input_string
else:
return None
def parse_dms(coord_string):
pattern = r'(\d+);(\d+);([\d.]+)'
match = re.match(pattern, coord_string)
if match:
degrees = int(match.group(1))
minutes = int(match.group(2))
seconds = float(match.group(3))
return degrees, minutes, seconds
else:
return None
def dms_to_decimal(degrees, minutes, seconds):
return degrees + minutes / 60 + seconds / 3600
# Your specific example:
coord_string = 'Latitude: 39;53;0.6499999 Longitude: 116;9;24.4199999'
latitude_input_string, longitude_input_string = extract_lat_long(coord_string)
latitude_degrees, latitude_minutes, latitude_seconds = parse_dms(latitude_input_string)
longitude_degrees, longitude_minutes, longitude_seconds = parse_dms(longitude_input_string)
print(f"Latitude: {latitude_degrees, latitude_minutes, latitude_seconds} Longitude: {longitude_degrees, longitude_minutes, longitude_seconds}")
latitude_decimal = dms_to_decimal(latitude_degrees, latitude_minutes, latitude_seconds)
longitude_decimal = dms_to_decimal(longitude_degrees, longitude_minutes, longitude_seconds)
print(f"Latitude: {latitude_decimal} Longitude: {longitude_decimal}")
$ python convert.py
Latitude: (39, 53, 0.6499999) Longitude: (116, 9, 24.4199999)
Latitude: 39.88351388886111 Longitude: 116.15678333330555