spacer1
spacer2 1_1 1_2
2_1
 Subscribe
 The MP2K Update!
 
 
 
 Magazine
Front Cover
What's New
Articles
News
Sample Data
Gallery
Advertise
About
 Features
MapPoint 2013
Press Releases
MapPoint Forums
Companies
Link to MP2Kmag
Wish List
MapPoint Trial
Authors
 Earlier Content
Past News Items
Past What's New Announcements
 Sponsors
 Order

MapPoint 2013

Programming MapPoint in .NET

MapPoint Book

  Spatial Community
SVG Tutorials
MapPoint

Map Visitors

  MAPPOINT Q & A  

Top | Post New Question | Read All | MP2K Asks Microsoft

694 Sohail - May 30, 2002

When I enter just a zipcode in MapPoint, it returns , , but not the city. Is it possible to get this information somehow? For example, I enter 46038 in MapPoint and search for it. MapPoint returns "46038, Indiana, United States". I cannot determine the city from StreetAddress object because it is set to nothing in this instance. Is there way to get the city for this zipcode? (which is Fishers in this case).

Answer:
June 4, 2002
I don't remember where this code originally came from (Gilles Kohl?), but here it is. It returns "Fishers area" for 46038.

Private Sub cmdGetCity_Click()
    Dim oMap As MapPointCtl.Map
    Dim oCityLoc As MapPointCtl.Location
    
    'Set the map object to the current map
    Set oMap = ctlMapPoint.ActiveMap
    
    Dim zipCode As String
    zipCode = txtZip.Text
    
    Set oCityLoc = FindCityForZipCode(zipCode, oMap)
    If Not (Nothing Is oCityLoc) Then
        txtCity = oCityLoc.Name
    Else
        txtCity = "Couldn't find city for this ZIP Code."
    End If

End Sub

Function FindCityForZipCode(strZip As String, oMap As MapPointCtl.Map) As MapPointCtl.Location
    Dim oZipLoc As MapPointCtl.Location
    Dim oZipResults As MapPointCtl.FindResults
    
    Set oZipResults = oMap.FindAddressResults(, , , , strZip, "USA")
    
    ' If it’s not a good match, then don’t accept it
    If geoFirstResultGood = oZipResults.ResultsQuality Then
        Set oZipLoc = oZipResults(1)
    Else
        Exit Function
    End If
    
    '  Must be a match to a Post Code (US ZIP Code)
    If Not (geoShowByPostal1 = oZipLoc.Type) Then
        Exit Function
    End If

    ' Go to the ZIP Code location on the map to hit test
    oZipLoc.GoTo
    Dim x As Integer
    Dim Y As Integer
    x = oMap.LocationToX(oZipLoc)
    Y = oMap.LocationToY(oZipLoc)
    
    ' Find all geographic entities at that point
    Dim oContext As MapPointCtl.FindResults
    Set oContext = oMap.ObjectsFromPoint(x, Y)
    
    ' Return the city at that point (if any)
    For Each obj In oContext
        If geoShowByCity = obj.Type Then
            Set FindCityForZipCode = obj
            Exit Function
        ElseIf geoShowByDefault = obj.Type Then
            Set FindCityForZipCode = obj
        End If
    Next obj

End Function

- Walt Cygan

Post New Answer / Follow-up


Google
 
MP2Kmag Internet


 Recent Discussion
 Resources


Want Your Site To Appear Here?

   © 1999-2012 MP2K. Questions and comments to: website@mp2kmag.com
  Microsoft and MapPoint 2002/2004/2006/2009/2010/2011/2013 are either trademarks or registered trademarks of Microsoft.