View Single Post

  #2 (permalink)  
Old 12-17-2003
Mossoft Mossoft is offline
Member
Yellow Belt
 
Join Date: Feb 2003
Posts: 48
I have a similar/simpler/less accurate(but good enough for my purposes) method which I call when a point on the map is clicked, passing in the location's X and Y values:

Code:
Function FindNearestAddress(locX As Long, locY As Long) As String
'Mossoft2003
    Dim dblTolerance    As Double
    Dim blnFound        As Boolean
    Dim lngCount        As Long
    Dim fr      As MapPoint.FindResults
    Dim sa      As MapPoint.StreetAddress
    Dim obj     As Object
    Dim lngAttempt  As Long
    Dim ToleranceStep   As Long
    Dim dX      As Long
    Dim dY      As Long
    Const ALTITUDE_LIMIT = 15
    
    On Error Resume Next
    
    If mapWhere.ActiveMap.Altitude < ALTITUDE_LIMIT Then
    
        blnFound = False
        lngAttempt = 0
        ToleranceStep = ALTITUDE_LIMIT - mapWhere.ActiveMap.Altitude
        dX = locX
        dY = locY

        Do
            Set fr = mapWhere.ActiveMap.ObjectsFromPoint(dX, dY)
            For Each obj In fr
                Set sa = obj.StreetAddress
                If Not sa Is Nothing Then
                    FindNearestAddress = sa.Value & " (" & CStr(mapWhere.ActiveMap.Distance(mapWhere.ActiveMap.XYToLocation(locX, locY), obj)) & " miles)"
                    blnFound = True
                    Exit For
                End If
            Next
            If blnFound Then Exit Do
            lngAttempt = lngAttempt + 1
            Select Case lngAttempt Mod 8
                Case 1
                    dX = locX
                    dY = locY + ToleranceStep
                Case 2
                    dX = locX + ToleranceStep
                    dY = locY + ToleranceStep
                Case 3
                    dX = locX + ToleranceStep
                    dY = locY
                Case 4
                    dX = locX + ToleranceStep
                    dY = locY - ToleranceStep
                Case 5
                    dX = locX
                    dY = locY - ToleranceStep
                Case 6
                    dX = locX - ToleranceStep
                    dY = locY - ToleranceStep
                Case 7
                    dX = locX - ToleranceStep
                    dY = locY
                Case 0
                    dX = locX - ToleranceStep
                    dY = locY + ToleranceStep
                    ToleranceStep = ToleranceStep + 1
            End Select
        Loop While Not blnFound And ToleranceStep < (2 * ALTITUDE_LIMIT)
    End If
    
FNA_Exit:
    Exit Function
FNA_Error:
    Debug.Print "ERROR: " & Err.Description
    Resume FNA_Exit

End Function
The search pattern is an 8 pointed star eminating, and spiralling out, from the original point.
The altitude check is to ensure the view point is low enough to display address level locations.

M.
Reply With Quote