[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
[phpBB Debug] PHP Notice: in file [ROOT]/includes/session.php on line 2208: Array to string conversion
www.undertowsoftware.com • View topic - VB.Net code for using the GPS?
Page 1 of 1

VB.Net code for using the GPS?

PostPosted: Sat Mar 16, 2013 1:38 am
by George.Tan
Does anyone have some simple code of implementing the GPS module in VB.Net?

Re: VB.Net code for using the GPS?

PostPosted: Mon Mar 18, 2013 11:22 am
by MarkY
Here is some simple code on using the GPS in Vb.Net. Hope it helps.

Private Sub AxGPSPro1_OnChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxGPSPro1.OnChange
' You need this code to get the coordinates each time the GPS moves
' Make sure genlon and genlat are global variables

genlon = AxGPSPro1.Lon
genlat = AxGPSPro1.Lat
End Sub

Private Sub AxMapPro1_PaintAfter(ByVal sender As System.Object, ByVal e As AxMapPro80.IMapProEvents_PaintAfterEvent) Handles AxMapPro1.PaintAfter
' This makes sure it doesn't try to repaint if the coordinates are bad/empty
If ((genlon <> 0) And (genlat <> 0)) Then
' Get the handle to a bitmap to use to mark the GPS location
Dim imgHnd As Integer = 0
imgHnd = AxMapPro1.GetImageHandle("c:\develop\mappro80\gbg.bmp")
AxMapPro1.DrawGPSArrow(e.dc, genlon, genlat, 10, imgHnd)
Else
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Set the Com port, display the GPS panel and start tracking
AxGPSPro1.ComPort = 5
AxGPSPro1.DisplayOn = True
AxGPSPro1.Start()
End Sub

Re: VB.Net code for using the GPS?

PostPosted: Wed Mar 20, 2013 9:13 am
by George.Tan
Thanks, MarkY. I tried it on a brand new VB form, but it didn't work. Are you sure that's the minimum code I would need to make the GPS arrow track by just clicking on Button2 ? Like I said I tried it, but it just sat there doing nothing.

Re: VB.Net code for using the GPS?

PostPosted: Wed Mar 20, 2013 10:01 am
by MarkY
First, disclosure - I am NOT a Vb.Net expert, but I've coded with it enough to be comfortable with it.

Second, that was a minimalist example and makes some assumptions about your development environment and your gps. For example, the assumption is that your gps is connected to COM5 (see line of code in Button2). Is it? If not, you'd have to change that to whatever port your GPS is connected to.

Also, the example assumes that the baud rate is 4800 (the default). If it's not, you need to specify the correct baud rate. This example is for a GPS that sends NMEA sentences to COM5. If that is not the case, you need to change the appropriate parameters (see the pdf that came with GPSPro, it's pretty good).

This also points to a specific bitmap on drive C: Do you have that folder and bitmap? If not, you need to change that line of code.

If you want, post a copy of your code here (or you can PM it to me) and may be I can spot the problem.

Re: VB.Net code for using the GPS?

PostPosted: Wed Mar 20, 2013 11:02 am
by George.Tan
I don't know what you meant by PM -you the code, but here it is. As you can see, I didn't really changed a lot from what you had posted and I did account for my own COM port and my own bitmap.

BTW, thanks for sticking with me on this. It is really appreciated!


Private Sub AxGPSPro1_OnChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxGPSPro1.OnChange
' You need this code to get the coordinates each time the GPS moves
' Make sure genlon and genlat are global variables

Dim genlon, genlat As Double
genlon = AxGPSPro1.Lon
genlat = AxGPSPro1.Lat
AxMapPro1.Refresh()
End Sub

Private Sub AxMapPro1_PaintAfter(ByVal sender As System.Object, ByVal e As AxMapPro80.IMapProEvents_PaintAfterEvent) Handles AxMapPro1.PaintAfter
'This makes sure it doesn't try to repaint if the coordinates are bad/empty
If ((genlon <> 0) And (genlat <> 0)) Then
Dim imgHnd As Integer = 0
imgHnd = AxMapPro1.GetImageHandle("c:\bitmaps\arrow2.bmp")
AxMapPro1.DrawGPSArrow(e.dc, genlon, genlat, 10, imgHnd)
Else
End If
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
' Set the Com port, display the GPS panel and start tracking
AxGPSPro1.ComPort = 3
AxGPSPro1.Baud = 4800
AxGPSPro1.DisplayOn = True
AxGPSPro1.Start()
End Sub

Re: VB.Net code for using the GPS?

PostPosted: Wed Mar 20, 2013 10:48 pm
by MarkY
Well, the line of code you added (shown in Red below), ensures that he GPS coordinates are ALWAYS 0,0 so it would never work. Those two variables need to be declared global, i.e., outside any of the private subs!!!!!

Private Sub AxGPSPro1_OnChange(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AxGPSPro1.OnChange
' You need this code to get the coordinates each time the GPS moves
' Make sure genlon and genlat are global variables

Dim genlon, genlat As Double
genlon = AxGPSPro1.Lon
genlat = AxGPSPro1.Lat
AxMapPro1.Refresh()
End Sub

Re: VB.Net code for using the GPS?

PostPosted: Thu Mar 21, 2013 7:51 am
by George.Tan
Such a stupid mistake - what was I thinking (on better, NOT thinking) :(

Sure enough, once I made those variables global, my moving arrow appeared on the screen.

Thank you!

Re: VB.Net code for using the GPS?

PostPosted: Thu Mar 21, 2013 9:44 am
by UShadow
One word of advice, there is a re-centering variable in the GPS interface, but it doesn't do anything (well, at least I haven't been able to make it do anything) :-( All it does is tell you if the user has selected that option in the panel and then you can use it to make sure the map is centered.