Click here to Skip to main content
15,887,962 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
as I summed up in the title I developed a geolocation application with vb.net, mysql, on which, the tracking is done via the GM862-GPS module by the use of the $ GPSACP command which gives the lat/long result to send an sms containing utc time in hh: mm: ss.sss, the latitude in size [B] DDMM.MMMM [/ B] N / S, longitude in size [B] dddmm.mmmm [/ B] E / W ..........
I created a windows form interface by dividing it into two split containers: the first one is to enter search keywords (city, street or lat/long), and the second that shows the google map as a response to research by latitude and longitude, and this is where I find my self bloqued and ask my question:
I defined two text boxes for lat and aconvert button, two text boxes for long and a convert button to convert the data value GM862-gps DDMM.MMMM in a real number and click search to find the map as a result to the lat and long queries: if I input the dddmm.mmmm format without conversion, the mapping doesen't work, but if i insert real values it works, then how should I do to convert this format to a real number? thank you in advance:)
Posted

This is just pretty basic arithmetic:
VB
Dim rawValue, degrees, minutes as Double
rawValue = Val("dddmm.mmmm")      ' Use the actual number string here
degrees = Int(rawValue / 100.0)
minutes = rawValue - (degrees * 100.0)
degrees = degrees + (minutes / 60.0) 

Of course, you could do it by taking the string apart and parsing the degrees and minutes separately...
 
Share this answer
 
v3
Comments
fridrai raissi 27-Jun-13 20:23pm    
thx matt for answering :)
i would like to ask u about the textbox on which i'll paste the "gm862-lat" to convert through a button on a new one, what should i do to make the written lat convertable?
should i just copy and paste this text on the convert-button-onclick sub?
and what did you mean by this part:
rawVaue - Val("dddmm.mmmm") ' Use the actual number string here ?
is the notification related to the gm862answer that i'll insert in the first text box before clicking on convert button?
thanks again :)
Matt T Heffron 28-Jun-13 13:27pm    
First I just fixed a couple of typo's I missed.
The comment on the Val("dddmm.mmmm") line meant that instead of the "dddmm.mmmm" exact string, here should be the string value you got back from the API.
For a text input, I would probably NOT use this format, but either degrees and minutes as separate text boxes or just degrees as a real string. Unless you have a specific reason, I'd hide the API format (dddmm.mmmm) from the users.
fridrai raissi 28-Jun-13 14:40pm    
target audience to excute the application are not simple people, to whom we should simplify the expression, they're security agents who manage the stolen articles' tracking :)
here is the python scrypt that i'll upload to gm8622 for tracking, would u like to take a view and tell me what's wrong? and should i make the ddmm.mmmm to real convertion directly on the tracker, so that the outgoing information be a "real number" one? i mean instead of converting on vb.net, i convert on python, i'll be gratefull if you agree to correct it :)
<pre lang="python">
##### Constants #####

TRUE = 1
FALSE = 0
LOOP = 1
SPEEDLIMIT = 30

##### Modules #####

#Use serial
import SER

#Use build in module
import MOD

#Use AT command interface
import MDM

#Use GPS
import GPS

###### General Functions ######

#Debug message
def errorsmg(msgtext):
somme = msgtext #msgtext = msgtext.replace('\r', '\\r')
#msgtext = msgtext.replace('\n', '\\n')
print (somme)

SER.send(msgtext + '\r\n')
#f = open('log.txt','ab')
#f.write(msgtext + '\n')
#f.close()

#GPS status
def gps_status(gpspos):
debugmsg('Retrieving GPS status')

gpspos_parts = gpspos.split(',')

if ( (gpspos_parts[5] == '2') or (gpspos_parts[5] == '3') ): #2D or 3D fix
#debugmsg('GPS fix "' + gpspos_parts[5] + '" ie valid');
status = TRUE
else:
#debugmsg('GPS fix "' + gpspos_parts[5] + '" ie not valid');
status = FALSE

return status

###### SMS Library Functions ######

#Setup SMS
def sms_setup():

debugmsg('Setting up SMS')

MDM.send('AT+CMGF=1\r', 0)
res = MDM.receive(50)#5 sec
MOD.sleep(1)#wait 0.1sec

debugmsg('SMS setup: ' + res)

def testspeed(gpspos):

#debugmsg('Test if speed is over limit')

gpsdataparts = gpspos.split(',')
currentspeed = gpsdataparts[7]
debugmsg('Time is ' + gpsdataparts[0] + ' UTC time')
debugmsg('latitude is ' + gpsdataparts[1])
debugmsg('longtitude is ' + gpsdataparts[2])
debugmsg('heading is ' + gpsdataparts[6])
debugmsg('Speed is ' + gpsdataparts[7] + ' km/hr')
debugmsg('date is ' + gpsdataparts[9])

if (gps_status(gpspos) == TRUE):
debugmsg('Has GPS Fix')
if (float(gpsdataparts[7]) < 60.0):
debugmsg('Speed UNDER the speed limit')

else:
debugmsg('Has NO GPS Fix to be tested for overspeeding')



SER.set_speed('115200','8N1')
SER.send('\r\n--------------------\r\n\r\n')

debugmsg('Running...');

#Set verbose error reporting
MDM.send('AT+CMEE=2\r', 0)
MDM.receive(50)#5 sec
MOD.sleep(1)#wait 0.1sec

#Setup SMS
sms_setup()

#Main loop
while (LOOP==1):

debugmsg('Entering loop')

#Retrieve current position
gpspos = GPS.getActualPosition()

debugmsg('Position: %s' % gpspos)

#Retrieve GPS fix status
gps_statusnow = gps_status(gpspos)

#Save last valid position
#If position fix valid, or none recorded already, use last retrieved
if ( (gps_statusnow == TRUE) or (gps_statusnow == FALSE) ):
testspeed(gpspos)

debugmsg('Powersave for 10 seconds')

#Powersave for 10 seconds
MOD.powerSaving(10)

</pre>
Matt T Heffron 28-Jun-13 14:43pm    
Sorry, I don't know Python.
I suggest you ask this as a NEW question.
thx again maatt
then explain me more plz how to define the conversion function through a button:
VB
Private Sub buttonconvert_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonconvert.Click

    End Sub



i'd like through this button to link the two text zones, the first one in which i'll insert gm862 result, and by clicking on the button, on the second textbox will appear the real value that will be the search criteria on the map
 
Share this answer
 
first of all i should convert the text zone on a double
what do you think about this way?
can we forward from strin g to double?
 
Share this answer
 
Comments
Matt T Heffron 28-Jun-13 17:13pm    
When I suggested, above, that you ask as a NEW question, I meant using the "Ask a Question" button on the "quick answers" page. That way they'll have a different subject line that will encourage others to read and (hopefully) provide an answer.

Also, adding Solutions to your own question is generally considered a form of misuse of the CodeProject site, especially when used to ask a follow-up question. (It gives you reputation points that you should acquire only when assisting others.)
problem resolved :)
VB
Private Sub buttonconvertlong_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles buttonconvertlong.Click
		Dim DD, deg, min, sec As Double
		Dim dir As String
		deg = CDbl(gm862long.Text.Substring(0, 3))
		min = CDbl(gm862long.Text.Substring(3, 7))
		sec = min / 60
		dir = CStr(gm862long.Text.Substring(11, 1))
		DD = deg + sec
		'Negative for West
		If dir = "W" Then
			DD = DD * -1
			txtlongitude.Text = CStr(DD)
		ElseIf dir = "E" Then
			'positive for East
			txtlongitude.Text = CStr(DD)
		End If
	End Sub
 
Share this answer
 
Comments
Matt T Heffron 1-Jul-13 12:54pm    
For the sake of anyone who will maintain this later on, the min / 60 is NOT in seconds at that point. It is now the fractional part of the measurement in degrees (which is why you can add it to deg and get the correct result). It should be named appropriately, or avoid the variable altogether:

DD = deg + min / 60
Also, the conditional for direction can be substantially simplified:

If dir = "W" Then
DD = -DD
End If
txtlongitude.Text = CStr(DD)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900