How to continuosly add a GPS pushpin on MP2006?

joseph975
10-20-2007, 03:33 PM
Hi everyone: I have to say Thank you!!!! for the wealth of information everyone on this post is sharing about mappoint. Information which for the most part, is not found anywhere else.

I am using vb6 and mp2006, and I am also new to programming. ---- Problem: I do not know how to continually display the lat/lot information coming from my GPS. I have two "Public" variables one for latitude (lat) and another one for longitude (lot) which are constantly receiving the already parsed lat/lot coordinates from the GPS, but the GetLocation method allows me to place only one pushpin on on the map. (See the last procedure below) What code do I use to place one pushpin every 1 or 2 seconds on the map based on the lat/lot info from the GPS?

code below:

--------------------------------------------------------------------------

Public lat As Double
Public lon As Double

Private Sub Form_Load()
Dim objMap As MapPointCtl.map
Set objMap = MappointControl1.NewMap(geoMapNorthAmerica)
Set objMap = MappointControl1.ActiveMap
call position_gps
End Sub

Private Sub form_unload(cancel As Integer)
MappointControl1.ActiveMap.Saved = True
End Sub

Private Sub position_gps()
Dim mymap As MapPointCtl.map
Dim myLoc As MapPointCtl.Location
Dim mypushpin As MapPointCtl.Pushpin
Set mymap = MappointControl1.ActiveMap
Set myLoc = mymap.GetLocation(lat, lon)
Set mypushpin = mymap.AddPushpin(myLoc)
mypushpin.Symbol = 83
mypushpin.Location.GoTo

End Sub

--------------------------------------------------------------------------

There is one or two similar threads, but no code is posted on the solution to this question.

Mattys Consulting
10-21-2007, 10:33 AM
Hi Joseph,

If you're trying to create a trail, "every one or two seconds" isn't even useful.
Besides, the refreshing of the screen will be continuous - you see no changes
until the screen is 'at rest.'

If you're only trying to track a vehicle, declare a variable as PushPin
and then change the location of the pin instead of adding new ones.

Mike Mattys

joseph975
10-22-2007, 12:02 AM
Thank you for your reply!

The code I have adds one pushpin to the map. How do I change/update the coordinates to a pin already on the map?

Joseph

Mattys Consulting
10-22-2007, 12:34 PM
Hi Joseph,

Sorry, workday ...

I believe I'd just do this:

[Aircode]
Set myLoc = mymap.GetLocation(lat, lon)
Set mypushpin.location = myLoc.location

Mike Mattys

joseph975
10-23-2007, 06:03 PM
Mike:

The code is still not compiling properly, I am getting a "variable not set" error. The object.location property seems to be the way to do it, but something I am doing is obviously wrong.

Just like you suggested, the "Programming Mappoint in .NET" book has a section which describes this process in C# , and although the code is different to VB6 the steps are similar:

currPushpin.Location = myloc; (in C#)

This is where the pushpin is supposed to keep updating its location from the myloc variable.

If I use the code you suggested:

Set myLoc = mymap.GetLocation(lat, lon)
Set mypushpin.location = myLoc.location

without adding the pushpin first with ...AddPushpin(myloc) I get a "variable not set" error.

If I use the following code:

Set myLoc = mymap.GetLocation(lat, lon)
Set mypushpin = mymap.AddPushpin(myLoc)
Set mypushpin.location = myLoc.location

I do not think it is correct to set a variable twice like that; therefore, the code does not produce the desired outcome. It just adds the pin, but no update.

Thank you again for your time and ideas. If you can think of any other way to fix this problem, any other suggestion is always welcome.

Joseph.

Mattys Consulting
10-24-2007, 09:25 AM
Let's say you have a menu item by the name of mnuExample
This will demonstrate how to continuously move your pushpin.

Private Sub mnuExample_Click(Index As Integer)
Dim MyMap As MapPoint.Map
Dim MyPin As MapPoint.Pushpin
Dim MyLoc As MapPoint.Location
Dim iloc As Long
Dim dlat As Double, dlon As Double

dlat = 43.223
dlon = -77.573
Set MyMap = MapCtl.Object.ActiveMap
Set MyLoc = MyMap.GetLocation(dlat, dlon, 1)
Set MyPin = MyMap.AddPushpin(MyLoc)
MyPin.Location.GoTo

For iloc = 0 To 200
Set MyPin.Location = MyMap.GetLocation(dlat, dlon, 1)
dlat = dlat + iloc / 1000
dlon = dlon + iloc / 1000
Set MyLoc = MyMap.GetLocation(dlat, dlon, 1)
MyPin.Location.GoTo
Next

Set MyLoc = Nothing
Set MyMap = Nothing
End Sub

Mike Mattys

 
Web mp2kmag.com
mapforums.com