I'm doing project for reading metadata of images. How can I convert GPS data in string like Latitude: 34 deg 30' 28.71" N to decimal degrees in float or double in C#? to running process
Asked
Active
Viewed 294 times
-1
-
Can you show us what exactly is the string you receive? Maybe you will have to do a converter which suits you. Cheers – Petar Stojanovski Mar 08 '19 at 10:34
-
Please take a look at [this](https://stackoverflow.com/questions/4983766/getting-gps-data-from-an-images-exif-in-c-sharp) to see if it is really this you're trying to do. – Lasse V. Karlsen Mar 08 '19 at 10:35
-
Are you asking how you can parse and tokenize a string? – Kieran Devlin Mar 08 '19 at 10:42
-
for example a have the string =(" 34 deg 30'40" ") how can i use any function to convert to value like lat= 34,56 – HueNguyen Mar 08 '19 at 10:47
1 Answers
-1
You need to use this simple formula, after extracting values from string.
Dim strGPS As String = "Latitude: 34 deg 30' 28.71"" N"
Dim degrees As Double = CDbl(strGPS.Split(Space(1))(1)) '34
Dim minutes As Double = CDbl(strGPS.Split(Space(1))(3).Replace("'", "")) '30
Dim seconds As Double = CDbl(strGPS.Split(Space(1))(4).Replace("""", "")) '28.71
MsgBox(degrees + (minutes / 60) + (seconds / 3600))

tezzo
- 10,858
- 1
- 25
- 48
-
-
added simple code in VB.NET to extract values from string; you can find better method if you need/want. – tezzo Mar 08 '19 at 10:50