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
Results 1 to 3 of 3

Extracting a Zip Code from a Pushpin

This is a discussion on Extracting a Zip Code from a Pushpin within the MapPoint Desktop Discussion forums, part of the Map Forums category; I've seen alot of posts for people wanting to extract location information from a pushpin. The VB code below places ...

  1. #1
    null_ethos is offline Junior Member White Belt
    Join Date
    Feb 2007
    Location
    Sain Louis, MO
    Posts
    2

    Lightbulb Extracting a Zip Code from a Pushpin

    I've seen alot of posts for people wanting to extract location information from a pushpin. The VB code below places a pushpins across the United States in a grid were the pushpins are 1 degree latitude and longitude away from each other. As the pushpins are placed their zip code location is determined and pushpin.name = location.name. It also deletes any pushpin that does not have a zip code for a name:If Len(PushPin.Name) <> 5 Then PushPin.Delete(). If you have any questions feel free to email me or reply back to the post

    Code:
    Public Sub ZipCodeLocator()
        Dim ActiveMap As MapPoint.Map
        Dim PushPin As MapPoint.Pushpin
        Dim FindResult As MapPoint.FindResults
        Dim xLocation As MapPoint.Location
    
        Dim CurrentLat As Double
        Dim CurrentLon As Double
    
        Dim StartLat As Double
        Dim StartLon As Double
        Dim StopLat As Double
        Dim StopLon As Double
    
        Dim X As Integer
        Dim Y As Object
    
        Dim Obj As Object
        Dim Null As System.DBNull  
    
    '  /////////////////////////////////////////
    ' //A new map must already be open//
    '////////////////////////////////////////
            
    StartLat = 48.9
    StartLon = -124
    StopLat = 24.9
    StopLon = -67
    
    CurrentLat = StartLat
    CurrentLon = StartLon
    
    X = 0
    Y = 1
    
            While (CurrentLat >= StopLat)
    
                xLocation = ActiveMap.GetLocation(CurrentLat, CurrentLon, 2000)
                'Altitude is important!!!, depending on what you want to
                'search for you may need to adjust this
    
                PushPin = ActiveMap.AddPushpin(xLocation)
                FindResult = ActiveMap.ObjectsFromPoint(ActiveMap.LocationToX(xLocation), ActiveMap.LocationToY(xLocation))
                xLocation.GoTo()
    
                For Each Obj In FindResult
                    X = X + 1
                Next
    
                While (Y <= X)
                    xLocation = FindResult.Item(Y)
                    If (xLocation.Type = MapPoint.GeoShowDataBy.geoShowByPostal1) Then
    'GeoShowDataBy can be changed to anything you want to search for
    
                        PushPin.Name = xLocation.Name
                        Y = X + 1
                    Else
                        Y = Y + 1
                    End If
                End While
    
                If Len(PushPin.Name) <> 5 Then PushPin.Delete()
                'Deletes the pushpin if the name is not a 5 digit zip code
    
                CurrentLon = CurrentLon + 1
                X = 0
                Y = 1
    
                'I am not sure why but I got errors when I did not reset these
                'values to null, probably a memory leak
                xLocation = Null
                PushPin = Null
                FindResult = Null
    
    
                If (CurrentLon = StopLon) Then
                    CurrentLon = StartLon
                    CurrentLat = CurrentLat - 1
                End If
            End While
        End Sub

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

    Re: Extracting a Zip Code from a Pushpin

    Hi,

    Yes this is the way to do it. Thanks for sharing, it will benefit many people. I see you use a very high altitude and the pushpins 1 degree from each other. I mostly use a low altitude and the locations mutch more near to each other. I dont know if the result is the same. Did you expermiment this way too ?

  3. #3
    null_ethos is offline Junior Member White Belt
    Join Date
    Feb 2007
    Location
    Sain Louis, MO
    Posts
    2

    Re: Extracting a Zip Code from a Pushpin

    My goal with this piece of code was to find zipcodes that were approximately 50 miles apart ( 1 degree lat and lon) and then export those location out of mappoint and into excell. I found that different altitudes will give you different results, too close in and you miss more general results and too far out and you miss detailed results. I used 2000 as my altitude simply because it was the first altitude I found that would return zip codes for me.

    If someone wanted to adjust the distance between points more acurately they could use the Haversign formula to find a longitude and latitude an exact distance from a location. Then depending on the kind of results they wanted they could change the if(xLocation = Mappoint.geoShowDataby.GeoShowbyPostal1) in the "ZipLocator" subroutine to any result type. The result type you want will determine the altitude you should use (which is found through trial and error unless someone knows what altitude ranges return what result types).

Thread Information

Users Browsing this Thread

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

Similar Threads

  1. Extracting Zips form the territory (from code)
    By andrejd in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 02-17-2006, 07:57 AM
  2. Extracting the corresponding Territory to a PushPin Location
    By jpendegraft in forum MapPoint Desktop Discussion
    Replies: 3
    Last Post: 08-13-2005, 03:06 AM
  3. Need help for extracting Populated Places !
    By dmincu in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 04-07-2003, 04:12 PM
  4. Extracting information from MapPoint?
    By oitsubob in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 03-10-2003, 09:36 AM
  5. Extracting to Excel
    By Anonymous in forum MapPoint Desktop Discussion
    Replies: 1
    Last Post: 12-13-2002, 11:38 AM

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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96