HOW TO
The following code shows how to add an existing geocoding service to an ArcMap document and make it the current locator.
Code:
Set pLocWS = pLocManager.GetLocatorWorkspaceFromPath("")
Code:
Set pLocWS = pLocManager.GetLocatorWorkspaceFromPath("d:\work")
Note:
Code in the Project's ThisDocument code module only runs in the current map document. To store the code in all of the map documents, open the Normal.mxt ThisDocument code module instead.
Code:
Public Sub test()
AddLocatorToArcMapAndMakeItTheCurrentLocator "robe2211.test_gs"
End Sub
Private Sub AddLocatorToArcMapAndMakeItTheCurrentLocator(locName As String)
Dim pUID As UID
Set pUID = New UID
pUID.Value = "esricore.locatorextension"
Dim pLocatorExtension As ILocatorExtension
Set pLocatorExtension = Application.FindExtensionByCLSID(pUID)
Dim pLocManager As ILocatorManager2
Set pLocManager = New LocatorManager
Dim pLocWS As ILocatorWorkspace
'This line of code is for standard Geocoding Services
Set pLocWS = pLocManager.GetLocatorWorkspaceFromPath("")
'If you are working with Server comment out the line above and uncomment the following lines.
'Dim pAGSConn As IAGSServerConnectionName
'Set pAGSConn = New AGSServerConnectionName
'Dim pProps As IPropertySet2
'Set pProps = New PropertySet
'pProps.SetProperty "machine", "testserver"
'pAGSConn.ConnectionProperties = pProps
'Dim pName As IName
'Set pName = pAGSConn
'Dim pAGSServerConnection As IAGSServerConnection
'Set pAGSServerConnection = pName.Open
'Set pLocWS = pLocManager.GetAGSLocatorWorkspace(pAGSConn)
Dim pLoc As ILocator
Set pLoc = pLocWS.GetLocator(locName)
Dim lng As Long
lng = pLocatorExtension.AddLocator(pLoc)
pLocatorExtension.CurrentLocator(pLoc.Category) = lng
End Sub
Article ID:000006098
Get help from ArcGIS experts
Download the Esri Support App