| Finding county for given city/state
Here's the approach I used to find the county of a city in pseudocode:
Sub Procedure GetCountyForCity(<strCity>, <strState>) as String
1. Get map object (active map)...objMap
2. Declare and set a location object:
>objLoc = objMap.FindResults(<strCity> & ", " & <strState>).Item(1)
3. Go to and select the location:
>objLoc.GoTo
>objLoc.Select
4. Declare and set a Results object:
>objRes = objMap.ObjectsFromPoint(objMap.LocationToX(objLoc) , objMap.LocationToY(objLoc))
5. Declare a set a boolean county found flag and temp county name variable
>bCountyFound = False
>strCounty = ""
6. Step through the results and find the object with type = 17 (geoShowDataByRegion2 for US counties)
>For i = 2 To objRes.Count 'index of 1 has no type and generates error
>>>If objRes.Item(i).Type = 17 Then
>>>>>>strCounty = objRes.Item(i).Name 'County found!
>>>>>>bCountyFound = True
>>>>>>Exit for
>>>End If
7. Return the results
>GetCountyForCity = strCounty
End Sub
In the calling procedure, you can test for "" county to see if you got one.
Specific syntax of course dependent on the language you'll be using.
Hope this is clear...let me know if you have questions. |