AnsweredAssumed Answered

Arcgis Engine - Locate an address on map issue

Question asked by geonetadmin on Jul 22, 2012
Original User: avm


I am developing a VB.Net geosearch application using Arcgis Engine. I am using the Arcgis online services to locate an address in the map control. The problem i am facing is that the point is slightly away from the actual address.

I have attached two images.

1. Engine_Map.jpg is the map generated using the arcgis engine geosearch application.
2. Javascript_Map.jpg is the map generated for the same address using arcgis javascript api.

In Engine_Map.jpg the pin (blue circle) is slightly away from the house. I want it to be like in Javascript_Map.jpg

Any help is greatly appreciated.


Code used to locate map:

Dim connectionProperties As IPropertySet = New PropertySetClass()
        connectionProperties.SetProperty("Url", "") '

        ' Open a workspace with an ArcGIS Server connection
        Dim obj As System.Object = Activator.CreateInstance(Type.GetTypeFromProgID("esriGISClient.AGSServerConnectionFactory"))
        Dim AGSServerConnectionFactory As IAGSServerConnectionFactory = CType(obj, IAGSServerConnectionFactory)
        Dim AGSServerConnection As IAGSServerConnection = AGSServerConnectionFactory.Open(connectionProperties, 0)

        ' Get the locator workspace from the open workspace
        obj = Activator.CreateInstance(Type.GetTypeFromProgID("esriLocation.LocatorManager"))
        Dim locatorManager As ILocatorManager2 = CType(obj, ILocatorManager2)
        Dim agsServerConnectionName As IAGSServerConnectionName = CType(AGSServerConnection.FullName, IAGSServerConnectionName)
        Dim locatorWorkspace As ILocatorWorkspace = locatorManager.GetAGSLocatorWorkspace(agsServerConnectionName)
        Dim AGOLLocator As ILocator = locatorWorkspace.GetLocator("Locators/TA_Address_NA")
        Dim addressGeocoding As IAddressGeocoding

        ' get the locator we created above
        addressGeocoding = CType(AGOLLocator, IAddressGeocoding)

        ' Get the address inputs for the locator
        Dim addressInputs As IAddressInputs = CType(AGOLLocator, IAddressInputs)
        Dim addressFields As IFields = addressInputs.AddressFields
        Dim fieldCount As Integer = addressFields.FieldCount
        Dim addressFieldNames(fieldCount) As String
        For j As Integer = 0 To fieldCount - 1
            addressFieldNames(j) = addressFields.Field(j).Name

        ' Set the Address that will be geocoded
        Dim addressProperties As IPropertySet = New PropertySetClass()
        addressProperties.SetProperty(addressFieldNames(0), address)
        addressProperties.SetProperty(addressFieldNames(1), city)
        addressProperties.SetProperty(addressFieldNames(2), state)
        addressProperties.SetProperty(addressFieldNames(3), zip)
  ' geocode the address
        Dim matchProperties As IPropertySet = addressGeocoding.MatchAddress(addressProperties)
        score = Convert.ToDouble(matchProperties.GetProperty("Score"))
  ' get the coordinates if any, and display the point on the map
        Dim possibleMatches As IFields = addressGeocoding.MatchFields
        If possibleMatches.FieldCount = 0 Then
            strWriter.WriteLine("No such address found")
            Exit Sub
        End If

        hookHelper = New HookHelperClass

        hookHelper.Hook = axMapControl1.Object
        Dim hookActions As IHookActions = CType(hookHelper, IHookActions)
        Dim geometriesArray As IArray = New ArrayClass()
        Dim addressArray As IStringArray = New StrArrayClass()
        Dim pt As IPoint
        Dim i As Integer = 0
        Do While i < possibleMatches.FieldCount
            Dim field As IField = possibleMatches.Field(i)
            If field.Type = esriFieldType.esriFieldTypeGeometry Then
                Dim point As IPoint = CType(matchProperties.GetProperty(field.Name), IPoint)
                If (Not point.IsEmpty) Then
                    'display the point on the map
                    'it is possible that the result returning has a different underlying spatial reference than the
                    'map's spatial reference. Therefore, you must reproject the search results geometries to the map's spatial reference
                    'before adding the geometries to the map.
                    If Not Nothing Is hookHelper.FocusMap.SpatialReference Then
                        If point.SpatialReference.FactoryCode <> hookHelper.FocusMap.SpatialReference.FactoryCode Then
                        End If
                    End If
                    addressArray.Add(address & ", " & zip)
                End If
            End If
            i += 1

        'do the different map actions. In this case, use the 'XXXMultiple' for the sake of efficiency and simplicity.
        hookActions.DoActionWithNameOnMultiple(geometriesArray, addressArray, esriHookActions.esriHookActionsCallout)
        hookActions.DoActionOnMultiple(geometriesArray, esriHookActions.esriHookActionsGraphic)
        hookActions.DoActionOnMultiple(geometriesArray, esriHookActions.esriHookActionsZoom)

        'Get IActiveView interface
        Dim pActiveView As IActiveView = CType(hookHelper.FocusMap, IActiveView)

        'Get IEnvelope interface
        Dim pEnvelope As IEnvelope = CType(pActiveView.Extent, IEnvelope)

        pEnvelope.Expand(0.0001, 0.0001, True)
        pActiveView.Extent = pEnvelope

        'call updatewindow in order to synch the map before flashing the new locations