How to geocode a single address

In this topic

Geocoding a single address

This topic discusses the two ways to geocode a single address by using IAddressGeocoding and MatchAddress, and by using a GeocodeServer.

Using IAddressGeocoding and MatchAddress

The following is the primary way to geocode a single address:
See the following code example:
public void GeocodeSingleAddress()throws IOException{
    // Open an AGSServerConnection.
    IPropertySet propertySetConnection = new PropertySet();
    propertySetConnection.setProperty("machine", "mendota");
    IAGSServerConnectionFactory agsServerConnectionFactory = new
    IAGSServerConnection agsServerConnection =
        (propertySetConnection, 0);

    // Open the AGSLocatorWorkspace.
    ILocatorManager2 locatorManager2 = new LocatorManager();
    IAGSServerConnectionName agsServerConnName = (IAGSServerConnectionName)
    ILocatorWorkspace locatorWorkspace = locatorManager2.getAGSLocatorWorkspace

    // Get a locator from the AGSLocatorWorkspace.
    ILocator locator = locatorWorkspace.getLocator("USA Streets");
    IAddressGeocoding addressGeocoding = (IAddressGeocoding)locator;

    // Geocode an address using the locator.
    IPropertySet propertySetAddress = new PropertySet();
    propertySetAddress.setProperty("Street", "380 New York St.");
    propertySetAddress.setProperty("City", "Redlands");
    propertySetAddress.setProperty("State", "CA");
    propertySetAddress.setProperty("ZIP", "92373");
    IPropertySet propertySetMatch = addressGeocoding.matchAddress(propertySetAddress)

    // Print the match properties.
    IFields fields = addressGeocoding.getMatchFields();
    IField field = null;
    IPoint point = null;
    for (int matchFieldIndex = 0; matchFieldIndex < fields.getFieldCount();
        field = fields.getField(matchFieldIndex);
        String field_name = field.getName();
        Object objectMatch = propertySetMatch.getProperty(field_name);
        if (field.getType() == esriFieldType.esriFieldTypeGeometry){
            point = (IPoint)objectMatch;
            if (!point.isEmpty()){
                System.out.println("X: " + point.getX());
                System.out.println("Y: " + point.getY());
            System.out.println(field.getAliasName() + ": " + objectMatch.toString());

Using a GeocodeServer

A GeocodeServer is a ServerObject delivered by an ArcGIS Server that can be used to geocode addresses. Internally, a GeocodeServer uses an address locator to do the geocoding and exposes the high-level functionality of the address locator using the IGeocodeServer interface.
Generally, GeocodeServer objects will be used by ArcGIS Server developers to create server applications that include geocoding functionality. However, ArcGIS Desktop and ArcGIS Engine developers can use GeocodeServer objects to include geocoding functionality in ArcGIS Desktop customizations and custom applications using only the high-level geocoding functionality exposed by a GeocodeServer.
See the following code example:
// Open a GISServerConnection.
IGISServerConnection serverConnection = new GISServerConnection();

// Get a GeocodeServer from the GISServerConnection.
IServerObjectManager som = serverConnection.getServerObjectManager();
IServerContext soc = som.createServerContext("USA Streets", "GeocodeServer");
IGeocodeServer geocodeServer = (IGeocodeServer)soc.getServerObject();

// Construct an address PropertySet to geocode.
IPropertySet addressProperties = (PropertySet)soc.createObject(PropertySet.getClsid()
addressProperties.setProperty("Street", "380 New York St.");
addressProperties.setProperty("City", "Redlands");
addressProperties.setProperty("State", "CA");
addressProperties.setProperty("ZIP", "92373");

// Set the geocoding properties to use to geocode the address.
IPropertySet locatorProperties = geocodeServer.getLocatorProperties();
locatorProperties.setProperty("MinimumMatchScore", "100");
locatorProperties.setProperty("SpellingSensitivity", "100");

// Geocode the address.
IPropertySet matchProperties = geocodeServer.geocodeAddress(addressProperties,

// Print the match properties.
IFields matchFields = geocodeServer.getResultFields(null);
for (int i = 0; i < matchFields.getFieldCount(); i++){
    IField field = matchFields.getField(i);
    if (field.getType() == esriFieldType.esriFieldTypeGeometry){
        IPoint point = (IPoint)matchProperties.getProperty(field.getName());
        if (!point.isEmpty()){
            System.out.println("X: " + point.getX());
            System.out.println("Y: " + point.getY());
            System.out.println(field.getAliasName() + ": " +

See Also:

How to geocode a table of addresses
Location library overview

Development licensingDeployment licensing
Engine Developer KitEngine
ArcGIS for Desktop BasicArcGIS for Desktop Basic
ArcGIS for Desktop StandardArcGIS for Desktop Standard
ArcGIS for Desktop AdvancedArcGIS for Desktop Advanced