View Single Post

  #2 (permalink)  
Old 12-18-2001
Walt Cygan Walt Cygan is offline
Senior Member
Green Belt
 
Join Date: Aug 2002
Posts: 124
No. The county information is not exposed anywhere in the data model as a property.


- Walt Cygan


Update: 12/23/2001 - The following message posted on the microsoft.public.mappoint newsgroup may help you.


Ken,



On Sat, 22 Dec 2001 07:35:03 -0600, "Ken Levy"

<kenlevy_deleteSpAm@home.com> wrote:



>Gilles:

>

>Thanks for the post. I checked out the reference you gave and found several

>good leads. One of the best, I think, was a dataset from the National

>Weather Service which contains time zone for each county in the US. Is

>there a way of getting the county name for a particular MP location object?



Try this (put it into a VB module):



Option Explicit



Public Function CountyFromLocation(oMap As MapPoint.Map, _

oOrgLoc As MapPoint.Location) As String

Dim oResults As MapPoint.FindResults



' Search for info

Set oResults = oMap.ObjectsFromPoint( _

oMap.LocationToX(oOrgLoc), _

oMap.LocationToY(oOrgLoc))



' define a generic object to iterate over FindResults

Dim oObj As Object



Dim oLoc As MapPoint.Location



CountyFromLocation = ""



' Loop over collection

For Each oObj In oResults

' Find out object type

If TypeOf oObj Is MapPoint.Location Then

Set oLoc = oObj ' Use Location object



' Got a county ?

If oLoc.Type = geoShowByRegion2 Then

CountyFromLocation = oLoc.Name

Exit Function

End If

End If

Next oObj



End Function


CountyFromLocation will return the name of the corresponding county,
given a map object, and a location. It will return an empty string
("") if no county was found.


Put the following into the code part of a VB form to test it:


Option Explicit

Dim oMpApp As MapPoint.Application

Dim WithEvents oMap As MapPoint.Map



Private Sub Form_Load()

Set oMpApp = GetObject(, "MapPoint.Application")

Set oMap = oMpApp.ActiveMap

End Sub



Private Sub oMap_BeforeClick(ByVal Button As Long, ByVal Shift As

Long, ByVal X As Long, ByVal Y As Long, Cancel As Boolean)

Dim oLoc As MapPoint.Location



Set oLoc = oMap.XYToLocation(X, Y)



Dim strCounty As String



strCounty = CountyFromLocation(oMap, oLoc)

If strCounty = "" Then strCounty = "No county found"

List1.AddItem strCounty

End Sub


The form should have a listbox List1 - each time you click in the map
(MapPoint should be running before you launch the program), it will
display its county guess in the listbox.



Regards,

Gilles [MVP].


P.S.: You may also want to check out
<http://www.mp2kmag.com/articles.asp?ArticleID=45> in this context -
this was used as the basis for the above.


--- Thanks, Gilles
Reply With Quote