Converting Latitude string to Float
pgbpsu
Posts: 460
I'm trying to convert a Latitude string to a float and I'm having LOTS of trouble. My GPS spits out a rather long string for the position:
ddmm.mmmmmm for latitude and dddmm.mmmmmm for longitude. I'm parsing the gps correctly (using Perry's GPS code). I know that because displaying the lat and lon works just fine:
To get these to floats I thought I'd strip off the integer degrees first, then the integer minutes, and finally the factional minutes. If I had those all as integers I could reassemble the position as a float.
What I'm unable to do is strip out certain parts of the string by position. I want to do something like this:
I realize I can't do that directly, but that's the idea behind what I want to do. It seems I need to make a buffer where I can temporarily store the substring:
I believe I have a pointer to the string containing the latitude which I need to copy into DD and null terminate:
This doesn't work, which unfortunately doesn't surprise me. I feel like I've come a long way with the Prop, but strings still baffle me!
Any suggestions???
Thanks,
pgb
ddmm.mmmmmm for latitude and dddmm.mmmmmm for longitude. I'm parsing the gps correctly (using Perry's GPS code). I know that because displaying the lat and lon works just fine:
uarts.str(debug,gps.latitude)
To get these to floats I thought I'd strip off the integer degrees first, then the integer minutes, and finally the factional minutes. If I had those all as integers I could reassemble the position as a float.
What I'm unable to do is strip out certain parts of the string by position. I want to do something like this:
DD := num_from_str(latitude[noparse][[/noparse]0..1]) intMM := num_from_str(latitude[noparse][[/noparse]2..3]) fracMM:= num_from_str(latitude[noparse][[/noparse]5..10])
I realize I can't do that directly, but that's the idea behind what I want to do. It seems I need to make a buffer where I can temporarily store the substring:
long degrees ' final location of degrees as int byte DD(4) ' make this long enough to hold DD or DDD and string terminator ' had to use () above because webpage wasn't showing brackets
I believe I have a pointer to the string containing the latitude which I need to copy into DD and null terminate:
bytemove(@DD,latitude,2) DD(2):=0 ' null terminal this string; same problem with () and brackets degrees := num_from_str(DD,DEC)
This doesn't work, which unfortunately doesn't surprise me. I feel like I've come a long way with the Prop, but strings still baffle me!
Any suggestions???
Thanks,
pgb
Comments
followed by: DD[noparse][[/noparse] 2 ] := 0
You could also do the conversion directly with:
degrees := (latitude[noparse][[/noparse] 0 ] - "0")*10 + (latitude[noparse][[/noparse] 1 ] - "0")
and:
intMinutes := (latitude[noparse][[/noparse] 2 ] - "0")*10 + (latitude[noparse][[/noparse] 3 ] - "0")
Post Edited (Mike Green) : 11/20/2008 5:17:13 PM GMT
Thanks for your suggestions. I've gotten it working. My problem was that latitude didn't actually contain the string. It was simply a pointer which I could call from outside the object. I wanted to add this method to the same object. Here's what I ended up with that was a combination of Mike's suggestion and Chuck's example code:
Thanks again to both of you.
pgb