MEINMEL

Address Locator returns nothing in FindAddress2008 sample - ArcGIS 10

Discussion created by MEINMEL on Jul 16, 2010
Latest reply on Jul 26, 2010 by MEINMEL
From ArcCatalog I created an address locator, style 'US Address - Dual Ranges'.  My locator fields includes definitions for Left/Right City, Zip and State.

From ArcMap I bring up the find, specifiy that locator, and geocode an address - without a city, state, or zip - that brings back 2 results.

When I attempt to use the same address locator in the FindAddress2008 sample it does not return any results for the same address unless I specify a city.

What am I doing wrong? 

Initialization:

            ' Get the locator
            obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
            locatorManager = TryCast(obj, ILocatorManager2)
            locatorWorkspace = TryCast(locatorManager.GetLocatorWorkspaceFromPath("C:\Maps\HillsboroughRoute\Hills_poly_gdb.gdb"), ILocatorWorkspace2)
            locator = TryCast(locatorWorkspace.GetLocator("Hillsborough_USStreets"), ILocator2)

This is the code from GeocodeAddress:

      Private Sub GeocodeAddress()
            Me.ResultsTextBox.Text = String.Empty
            txtStopWatch.Text = String.Empty

            _stopWatch.Reset()
            _stopWatch.Start()

            ' Set up the address properties
            Dim addressInputs As IAddressInputs = TryCast(locator, IAddressInputs)
            Dim addressFields As IFields = addressInputs.AddressFields
            Dim addressProperties As IPropertySet2 = New PropertySetClass()
            Dim arrayFieldName As Object = Nothing

            addressProperties.SetProperty(addressFields.Field(0).Name, Me.AddressTextBox.Text)
            addressProperties.SetProperty(addressFields.Field(1).Name, Me.CityTextBox.Text)
            addressProperties.SetProperty(addressFields.Field(2).Name, Me.StateTextBox.Text)
            addressProperties.SetProperty(addressFields.Field(3).Name, Me.ZipTextBox.Text)

            ' Match the Address
            Dim addressGeocoding As IAddressGeocoding = TryCast(locator, IAddressGeocoding)
            Dim resultSet As IPropertySet = addressGeocoding.MatchAddress(addressProperties)

            Dim addressCandidates As ESRI.ArcGIS.Location.IAddressCandidates2 = TryCast(locator, IAddressCandidates2)
            Dim simpleArray As IArray = addressCandidates.FindMatchingAddressCandidates(addressProperties)
            Dim memberFields As IFields2
            Dim candidatePropertySet As IPropertySet2
            Dim values As Object = Nothing

            ' Print out the results
            If simpleArray.Count > 0 Then
                memberFields = TryCast(addressCandidates.CandidateFields, IFields2)
                candidatePropertySet = TryCast(simpleArray.Element(0), IPropertySet2)
                If candidatePropertySet.Count > 0 Then
                    Try
                        Dim matchAddr As String = String.Empty
                        Dim cnt As Integer = 1
                        For matchFieldIndex As Integer = 0 To simpleArray.Count - 1
                            Me.ResultsTextBox.Text &= "Count " & cnt & " "
                            candidatePropertySet = TryCast(simpleArray.Element(matchFieldIndex), IPropertySet2)
                            If Not candidatePropertySet Is Nothing AndAlso candidatePropertySet.Count > 0 Then
                                ' different locators may not have the same properties
                                candidatePropertySet.GetAllProperties(arrayFieldName, values)
                                Dim nArray As String() = TryCast(arrayFieldName, String())
                                Dim vArray As Object() = TryCast(values, Object())
                                Dim lgth As Integer = nArray.Length
                                Dim pt As IPoint = Nothing
                                Dim i As Integer = 0
                                Do While i < lgth
                                    If nArray(i) <> "Shape" Then
                                        Me.ResultsTextBox.Text += nArray(i) & ": " & vArray(i).ToString() & Constants.vbLf
                                    Else
                                        If Not pt Is Nothing AndAlso (Not pt.IsEmpty) Then
                                            pt = TryCast(vArray(i), IPoint)
                                            Me.ResultsTextBox.Text &= "X: " & pt.X + Constants.vbLf
                                            Me.ResultsTextBox.Text &= "Y: " & pt.Y + Constants.vbLf
                                        End If
                                    End If
                                    i += 1
                                Loop
                            End If
                            Me.ResultsTextBox.Text &= Constants.vbLf
                            cnt += 1

                        Next
                    Catch ex As Exception
                        Debug.Print(ex.Message)
                    End Try
                End If
            End If

            Me.ResultsTextBox.Text &= Constants.vbLf

            Dim names As Object
            resultSet.GetAllProperties(names, values)
            Dim namesArray() As String = TryCast(names, String())
            Dim valuesArray() As Object = TryCast(values, Object())
            Dim length As Integer = namesArray.Length
            Dim point As IPoint = Nothing
            For i As Integer = 0 To length - 1
                If namesArray(i) <> "Shape" Then
                    Me.ResultsTextBox.Text += namesArray(i) & ": " & valuesArray(i).ToString() & Constants.vbLf
                Else
                    If point IsNot Nothing AndAlso (Not point.IsEmpty) Then
                        point = TryCast(valuesArray(i), IPoint)
                        Me.ResultsTextBox.Text &= "X: " & point.X + Constants.vbLf
                        Me.ResultsTextBox.Text &= "Y: " & point.Y + Constants.vbLf
                    End If
                End If
            Next i

            Me.ResultsTextBox.Text += Constants.vbLf

            txtStopWatch.Text = "Time to process: " & _stopWatch.Elapsed.ToString
            _stopWatch.Stop()

        End Sub

Outcomes