Welcome to MapForums!

Register, sign in, or use Facebook Connect above to join in and participate in the forum.

When you are signed in, this message, the ads in this row, and the red-underlined link ads all go away.

Subscribe to receive our newsletter.
Subscribe Unsubscribe

View Poll Results: Is the Curse of the Bambino finally broken?

Voters
3. You may not vote on this poll
  • Yes

    2 66.67%
  • No

    1 33.33%
Results 1 to 10 of 10

Placing PushPins using VBA programing

This is a discussion on Placing PushPins using VBA programing within the MapPoint Desktop Discussion forums, part of the Map Forums category; I am now to MapPoint automation and am in the midst of have to modify and existing MSAccess 2K application ...

  1. #1
    jburgess is offline Junior Member White Belt
    Join Date
    Oct 2004
    Posts
    7

    Placing PushPins using VBA programing

    I am now to MapPoint automation and am in the midst of have to modify and existing MSAccess 2K application that interfaces with the MapPoint 11 activeX object. My task is to read a table containing records where each record has a longitude and latitude field. My task is to do the following:

    Read each record, place a pushpin that looks like a green factory at the location indicated by its Long and Lat values.

    Has anyone been able to accomplish such a task and if so, is there any example visual basic code? Any help would be greatly appreciated.

    Thanks
    jburgess

  2. #2
    Winwaed's Avatar
    Winwaed is offline Mapping-Tools.com Black Belt
    Join Date
    Feb 2004
    Location
    Irving,Texas
    Posts
    1,859
    Blog Entries
    60
    I assume you have a copy of MapPoint? Looking the help. Under programming information, there are a number of pages about how to do specific things - eg. locations, routes, polygons.
    Look at the locations and pushpins example.
    You need to create a Location object from your lat/long coordinate.
    Then you create a pushpin object using the Location object.
    You can set the symbol type or load one of your own.



    Richard
    Winwaed Software Technology LLC
    http://www.winwaed.com
    See http://www.mapping-tools.com for MapPoint Tools

  3. #3
    mgravell is offline Junior Member White Belt
    Join Date
    Oct 2004
    Posts
    8

    re: Placing PushPins using VBA programing

    As an aside, I find that the app is quicker if I simply save the long/lats to a CSV and load it as a dataset; otherwise, I get "the curse of the flickering hourglass" as it adds each pin in turn.

    Just a thought; do it any way that makes you happy

  4. #4
    jburgess is offline Junior Member White Belt
    Join Date
    Oct 2004
    Posts
    7

  5. #5
    kikolino is offline Junior Member White Belt
    Join Date
    Feb 2008
    Posts
    9

    Placing PushPins using VBA programing

    I have also a problem with setting pushpins with a vba code. At first I calculte a distance matrix and afterwards I want to add a pushpin to each of my addresses, but it doesn´t work...
    Here is my code:

    Sub Distance()
    Dim oApp As New MapPoint.Application
    oApp.Visible = True
    oApp.UserControl = True
    oApp.ActiveMap.Saved = True
    oApp.Units = geoKm
    Dim objFindResults As MapPoint.FindResults
    Dim objLoc As MapPoint.Location
    Dim objPushpin As MapPoint.Pushpin
    Dim i As Integer
    Dim j As Integer
    Dim PLZ1, PLZ2 As String
    Dim STADT1, STADT2 As String
    Dim ADDRESSE1, ADDRESSE2 As String
    Dim dist As Double

    Set oApp = CreateObject("MapPoint.Application")
    Set objMap = oApp.ActiveMap
    Set objRoute = objMap.ActiveRoute
    For i = 2 To 4
    PLZ1 = Tabelle1.Cells(i, 2)
    STADT1 = Tabelle1.Cells(i, 3)
    ADDRESSE1 = Tabelle1.Cells(i, 4)

    For j = i + 1 To 4
    PLZ2 = Tabelle1.Cells(j, 2)
    STADT2 = Tabelle1.Cells(j, 3)
    ADDRESSE2 = Tabelle1.Cells(j, 4)

    objRoute.Waypoints.Add objMap.FindAddressResults(PLZ1, STADT1, ADDRESSE1).Item(1)
    objRoute.Waypoints.Add objMap.FindAddressResults(PLZ2, STADT2, ADDRESSE2).Item(1)
    objRoute.Calculate
    'Set objLoc = objMap.FindAddressResults(Plz1, stadt1, addresse1)
    'objMap.AddPushpin (objLoc)
    dist = objRoute.Distance
    Debug.Print i & "," & j
    Debug.Print "distance " & dist
    objRoute.Clear
    Next j
    Next i
    oApp.Quit
    End Sub

    When I run the makro without the red pushpin part everything works great. But with that part it doesn´t work. I don´t know how to add pushpins in this case but I know that the red part works in other makros...
    Can anybody help me?

    Already thanks
    Kikolino

  6. #6
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Placing PushPins using VBA programing

    Hi,

    You probably will have an exception if you step with the debugger trough it. FindAddressResults returns a collection of Location object, not a Location object. So something like this should work:
    Code:
    Dim objLocResults As MapPoint.FindResults;
    objLocResults = objMap.FindAddressResults(Plz1, stadt1, addresse1);
    objMap.AddPushpin(objLocResults_Item(1));
    Please check my syntax, as I'm not a VBA programmer

  7. #7
    kikolino is offline Junior Member White Belt
    Join Date
    Feb 2008
    Posts
    9

    Re: Placing PushPins using VBA programing

    Hi Wilfried!

    Thanks for your quick answer but unfortunately it doesn´t work... Even with the right syntax

    Set objLocResults = objMap.FindAddressResults(PLZ1, STADT1, ADDRESSE1)
    objMap.AddPushpin (objLocResults.Item(1))

    Runtime error 438 appears.

    Greetz Kikolino

  8. #8
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Placing PushPins using VBA programing

    Hi,

    You should first check the ResultsQuality property. Maybe there is no Location returned from that particular address. Sorry I was incomplete..

  9. #9
    kikolino is offline Junior Member White Belt
    Join Date
    Feb 2008
    Posts
    9

    Re: Placing PushPins using VBA programing

    Hi Wilfried!
    Thanks, but it still doesn´t work, always the same error... But there is a result found for the address.

    Greetz Kikolino

  10. #10
    Wilfried is offline Senior Member Black Belt
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    2,433

    Re: Placing PushPins using VBA programing

    Hi,

    then something else should be wrong. did you try a simple test like this? eventually with other addresses and so ? this is C# but you can easy translate it into VBA. Piece of code is tested:

    Code:
        int name = 1;
        FindResults addrResults = MP.ActiveMap.FindAddressResults("churchilllaan", "Schoten", "", "", "", GeoCountry.geoCountryBelgium);
        foreach (object o in addrResults) {
            Location loc = o as Location;
            if (loc == null)
                continue;
            MP.ActiveMap.AddPushpin(loc, name.ToString());
            name++;
        }

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Creating a subset of Pushpins from a set of pushpins
    By paf33 in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 08-09-2005, 05:54 AM
  2. Pl.. Help ----Locating/ placing positions in India
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 11-13-2003, 03:20 AM
  3. Programmatically Placing Pushpin on a Line
    By jbendiner in forum MapPoint Desktop Discussion
    Replies: 0
    Last Post: 01-05-2003, 11:18 PM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25