[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?

VB.Net code for using the GPS?

A forum made available for users of the MapPro OCX SDK to exchange ideas, ask each other questions, etc.

VB.Net code for using the GPS?

Postby George.Tan » Sat Mar 16, 2013 1:38 am

Does anyone have some simple code of implementing the GPS module in VB.Net?
User avatar
George.Tan
Active User
Active User
 
Posts: 25
Joined: Sat Mar 31, 2012 11:26 am

Re: VB.Net code for using the GPS?

Postby MarkY » Mon Mar 18, 2013 11:22 am

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
The gene pool has no lifeguard...
User avatar
MarkY
Active User
Active User
 
Posts: 28
Joined: Sat Feb 06, 2010 7:31 pm

Re: VB.Net code for using the GPS?

Postby George.Tan » Wed Mar 20, 2013 9:13 am

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.
User avatar
George.Tan
Active User
Active User
 
Posts: 25
Joined: Sat Mar 31, 2012 11:26 am

Re: VB.Net code for using the GPS?

Postby MarkY » Wed Mar 20, 2013 10:01 am

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.
The gene pool has no lifeguard...
User avatar
MarkY
Active User
Active User
 
Posts: 28
Joined: Sat Feb 06, 2010 7:31 pm

Re: VB.Net code for using the GPS?

Postby George.Tan » Wed Mar 20, 2013 11:02 am

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
User avatar
George.Tan
Active User
Active User
 
Posts: 25
Joined: Sat Mar 31, 2012 11:26 am

Re: VB.Net code for using the GPS?

Postby MarkY » Wed Mar 20, 2013 10:48 pm

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
The gene pool has no lifeguard...
User avatar
MarkY
Active User
Active User
 
Posts: 28
Joined: Sat Feb 06, 2010 7:31 pm

Re: VB.Net code for using the GPS?

Postby George.Tan » Thu Mar 21, 2013 7:51 am

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!
User avatar
George.Tan
Active User
Active User
 
Posts: 25
Joined: Sat Mar 31, 2012 11:26 am

Re: VB.Net code for using the GPS?

Postby UShadow » Thu Mar 21, 2013 9:44 am

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.
Imagination is greater than detail - Albert Einstein
User avatar
UShadow
Frequent User
Frequent User
 
Posts: 61
Joined: Fri May 28, 2010 11:49 am


Return to MapPro OCX

Who is online

Users browsing this forum: No registered users and 0 guests

cron