Search for places (geocoding)

Using a place name or street address as input, your user can find locations of interest and interact with them on the map. The process of matching locations on the map to an address is referred to as geocoding.

Geocoding overview

Address geocoding (or geocoding) is the process of using information contained in an address to interpolate a corresponding location on the map. An address may define a precise street location, such as 380 New York Street, Redlands CA 92373. It may provide only a general location, such as a city name or postal code, or it may be a familiar place name or landmark, such as Ayers Rock.

Using a reference data source, referred to as a locator, ArcGIS finds map locations by matching an input address with feature attributes. The number and accuracy of the geocoded results (often called matches or candidates) may vary depending on the specificity and quality of the input address provided. For example, the address New York is likely to return a match for the state of New York, the city of New York, and perhaps several streets or points of interest that share that name. Geocoded locations are always points. If a match is made with a polygon (a state or postal code, for example), the match location represents the center of that area.

Additional geocoding inputs can improve the relevance of results by restricting the search to a given area or finding matches that are near a reference location. This allows you to find results for a specified country, map extent, or near the user's current or anticipated location. A general search such as restaurant is unlikely to return useful candidates unless it is restricted to a specific area.

When several candidates are returned for an address, they are sorted by the quality of the match. This means it is generally safe to assume that the first candidate in the results represents the best match. Sometimes, however, you may want to examine a set of top candidates to determine the most appropriate match. Address candidates can contain the level at which they were matched (house, street, postal code, and so on) and the interpolated address created by the locator. Both of these may help you determine the best match or perhaps find problems in the original address input. If geocoding used a reference location, a distance attribute can help you find the closest candidate.

Caution:

The score attribute, an integer value ranging from 0 to 100, provides an estimate of relative match accuracy within a single locator. If you are using a composite locator (such as the ArcGIS World Geocoding Service), these values will represent the score within a locator for a specific level, but not an overall evaluation of the match. A score of 100 for a postal code match is not necessarily a more precise result, for example, than a score of 90 at the house level.

Addresses

Addresses are fundamental for geocoding and have some specific characteristics. An address is composed of one or more address elements: individual components of the address, such as house number, street name, street type, and postal code. Address elements help in the geocoding search, pinpointing an address to a particular location. Addresses come in various styles and formats, including street address, a place name, or a location that is identified by a code. A common address format used in the United States consists of the following series of address elements: house number, prefix direction, prefix type, street name, street type, suffix direction, and zone information (such as city, state, and ZIP Code). Globally, addresses are represented in a variety of formats. However, while all of these addresses differ to some degree, some things remain consistent. Each address consists of one or more address elements presented in a particular address format recognized by those in the region.

When geocoding, you can pass in individual components of an address or provide all information as a single string to be parsed. Defining each component of an address gives you more control but may require that you either parse the components before passing them to the locator or provide additional UI controls for your user to enter each piece of information.

When geocoding, the type of information expected in an input address is determined by the address style configured by the locator you're using. Some of the common address component field names for the ArcGIS World Geocoding Service (https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer) are listed below as examples of the types of input that may be expected. See Multiple input field geocoding for details.

  • Address—House number and street
  • Neighborhood—Subdivision of a city (not used for United States addresses)
  • City—City or municipality
  • Subregion—Administrative region, such as a county or province (not used for United States or Mexico addresses)
  • Region—Largest administrative boundary associated with the address (state name in the United States)
  • Postal—Postal code
  • CountryCode—Name or ISO code of the country

Locators

The fundamental logic for geocoding is built into the locator and does not come from your ArcGIS Runtime SDK code. The locator (created using ArcGIS Desktop) is the major component in the geocoding process and contains all the data necessary to perform address matching. If you'd like a ready-to-use and regularly updated locator (and network dataset) for your area of interest, you can license StreetMap Premium data (in MMPK format). For details, see Add StreetMap Premium data.

A locator is created based on a specific address locator style, which dictates what type of address input is expected and how matching will be carried out. The following table lists some of the common address styles, the type of matching that it enables, and an example of input address values:

Address styleDescriptionInput address examples

US Address - City State

Finds a city in the United States using reference data that stores city and state names

Bonita, CA

Punxsutawney, PA

US Address - Dual Ranges

Interpolates an address location using a streets reference dataset that includes number ranges for both sides of the street

30 E. State St, Redlands CA 92373

1060 W. Addison St, Chicago IL 60613

General - Gazetteer

Finds place names or landmarks worldwide using reference data with a place name attribute

Taj Mahal

Ypres

General - Single Field

Locates features using a specific field in the reference dataset

012883902

UTC330868-A

Note:

This is not a complete list of the available address styles. For a more complete description, see Commonly used address locator styles in the ArcGIS Desktop help.

Once created, an address locator contains a set of geocoding properties (preferences), a snapshot of the address attributes in the reference dataset, and the queries for performing a geocoding search. The address locator also contains a set of address parsing and matching rules that directs the geocoding engine to perform address standardization and matching.

A locator can be stored locally (as a *.loc file) or can be published as a locator service using ArcGIS Server. To perform geocoding, you need to access either an online locator or one available locally on the device. Using ArcGIS Runtime SDK, you can connect to a variety of online locators published and hosted by Esri, including address locators for Europe and North America, a street locator for the United States, and a world places locator. These services allow you to begin geocoding with online data right away without having to create and configure an address locator yourself. Locators can be created and configured with local data using ArcGIS Desktop as the authoring environment. See the ArcGIS help topic Creating an address locator for detailed information.

Results

Geocoding results for a particular address are referred to as candidates. Depending on how specific and complete the input address is, you may get several candidates from a geocode operation. Geocoding results are ordered by quality of the match, so the first candidate is generally the best. Additional candidate information can be obtained by specifying supplemental output fields to include in the results. The following table describes a few of the available fields you can include from the world geocoding service. This is only a representative list of fields. For a complete list, see Output fields in the ArcGIS REST API documentation.

Note:

The fields provided may vary between locators. See the Get locator info section of this topic for information about querying a locator for its available result attributes.

Output fieldDescription

Score

Value between 0 and 100 that describes the relative quality of the match within a single locator.

Match_addr

Complete address returned for the geocode request. The format is based on address standards for the country within which the address is located.

Addr_type

The match level for a geocode request. For example, a candidate that matches only to a postal code will have a value of Postal. Supported match levels vary in different countries. See Output fields for a description of possible values for this field.

Side

The side of the street on which the address was matched (relative to the direction of digitization of the reference line feature). Possible values are L (left), R (right), or an empty string (undefined).

Distance

The distance (meters) from the candidate to a specified location. The reference location needs to be specified as a parameter before executing the task.

Rank

A number indicating the importance of each candidate relative to others in the results. Rank is generally used to help distinguish ambiguous place names using population as the criterion. A search for Las Vegas, for example, may return Las Vegas, NV as the top ranked match (1) and Las Vegas, NM as a lower rank based on the relative population of those cities. If a reference location and distance parameters have been set for a find operation, distance from the reference location will be used to rank candidates.

Use a locator task

Geocoding is implemented using the LocatorTask class with an online or local locator. To implement this task in your code, follow these general steps:

  1. Create a LocatorTask using an online or local resource (locator service or file).
  2. Specify geocoding preferences using the GeocodeParameters object. This is optional but allows you to request additional attributes in the results, to restrict the search by area, set the maximum number of results, and so on.
  3. Execute the task, passing in any required parameters (such as address values and geocode parameters).
  4. Process the results (display a list of candidates for the user to choose from, display the best match as a graphic on the map, and so on).

You create a LocatorTask by passing a URI (for an online locator) or a path (for a local locator) to the static CreateAsync method on the class. The following example creates a new LocatorTask that uses the ArcGIS Online World Geocoding service.

var geocodeServiceUrl = @"http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";
LocatorTask geocodeTask = await LocatorTask.CreateAsync(new Uri(geocodeServiceUrl));

Note:
The World Geocoding Service from ArcGIS Online includes a for_storage parameter. Storing the results of a geocode or reverse geocode operation using this service (by setting the for_storage parameter to true) requires an ArcGIS Online paid subscription and uses credits from the subscriber's account. Additionally, the user performing a paid operation must be assigned a user role that includes the geocoding privilege. For more information, see Free vs. paid operations in the REST documentation for this geocode service and Levels, roles, and privileges in ArcGIS Online Help.

Get locator info

Before executing a geocode operation, you may need information about a particular locator to work with it effectively. You may need to know which input fields are used to locate an address, which attributes are available with the results, or the spatial reference in which the candidate locations will be returned by default. You can use LocatorInfo to get the following information about a locator:

  • Name—A string that identifies the locator
  • Description—A brief description
  • Result attributes—A list of field names that are available for results
  • Search attributes—A list of input fields used for multiline geocoding
  • Spatial reference—The spatial reference used by the locator (and the default coordinate system for results)
  • Support for intersections—A true or false value that indicates whether geocoding of street intersections is supported
  • Support for points of interest—A true or false value that indicates whether searching points of interest (POI) is supported
  • Support for suggestions—A true or false value that indicates whether the locator supports offering suggestions for addresses
  • Version—The version of the locator

The following example shows how you can use a LocatorTask to connect to an online locator service and get the names of available result attributes:

// get info from the LocatorTask
var locatorInfo = geocodeTask.LocatorInfo;


// loop through all attributes available to include in the results
foreach(var field in locatorInfo.ResultAttributes)
{
    // add the field's display name to a list box
    ResultFieldsList.Items.Add(field.DisplayName);
}

Geocode parameters

When geocoding an address or point of interest, you can optionally provide preferences to control certain aspects of the geocoding operation. The following list describes some of the properties you can control:

  • Country—The full name or code for the country to which geocoding should be restricted
  • Maximum results—A limit for the maximum number of address candidates to return
  • Output language—The language (culture) in which result attributes will be returned
  • Output spatial reference—The spatial reference in which geographic locations for address candidates will be returned
  • Result attributes—A list of field names to include in the results (available fields can be queried from the locator)
  • Search area—A geographic shape that defines an area to geocode within

A similar (more limited) set of preferences is available when getting a set of address suggestions, as described in the following section.

Get address suggestions

You can use a locator task to find suggestions for a partial address entry. As your user types an address, for example, a list of suggestions based on the first few characters of the address string can be displayed. Check LocatorInfo.SupportsSuggestions to see if a particular locator can provide address suggestions.

Suggested addresses

A search for address suggestions can optionally be restricted to a specified country or area on the map. To define a country, use the full name or ISO 3166-1 (two or three character) code. See Geocode coverage in the REST API documentation for a list of countries and corresponding codes. You can also indicate a preferred location (point) for the search, and set the maximum number of suggestions to return.

Tip:

Restricting your search or geocode operations to a specified country or location (as well as the number of results) can improve performance.

The following example calls the SuggestAsync method on a LocatorTask to get suggested addresses as the user types. A SuggestParameters object is used to restrict the search for suggestions to the current map extent.

// get suggestions if the locator supports them
if (_geocodeTask.LocatorInfo.SupportsSuggestions)
{
    // get the current map extent
    var currentExtent = MyMapView.GetCurrentViewpoint(ViewpointType.BoundingGeometry).TargetGeometry;
    // restrict the search to the current map extent and return no more than 10 suggestions
    var suggestParams = new SuggestParameters { MaxResults = 10, SearchArea = currentExtent };
    // get suggestions for the text provided by the user
    var suggestions = await _geocodeTask.SuggestAsync(AddressTextBox.Text, suggestParams);
    // show suggestions ...
    SuggestionsListBox.ItemsSource = suggestions;
}

The address suggestion results do not contain location information, only the full address text. To get a location, you must take the additional step of geocoding the suggestion as described in the following section.

Geocode an address

Use a LocatorTask to find geocode candidates from an address, point of interest, or address suggestion. An input address can be defined as a single string, such as 380 New York Street, Redlands CA 92373 or you can define the individual components of the address (such as number and street, city, region, postal code, and so on).

The following example defines an input address using a dictionary to hold each address component. Match candidates are then found by passing it to the GeocodeAsync method.

// create a dictionary of strings
var address = new Dictionary<string, string>();
// add each address component (keys and values)
address.Add("Address", "380 New York Street");
address.Add("City", "Redlands");
address.Add("Region", "CA");
address.Add("Postal", "92373");


// find matches for this address
var matches = await _geocodeTask.GeocodeAsync(address);

Tip:

You can use LocatorInfo to get the input address field names for a locator.

If you define the address as a single string, it will be parsed into the appropriate address components by the locator.

var matches = await _geocodeTask.GeocodeAsync("380 New York Street, Redlands CA 92373");

You can also geocode using a result from an address suggestion. The following example geocodes a suggested address as created in the Get address suggestions section of this topic.

// get the selected suggestion in a ListBox
var suggestion = SuggestionsListBox.SelectedItem as SuggestResult;
var matches = await _geocodeTask.GeocodeAsync(suggestion);

The following example matches a Japanese address with the ArcGIS World Geocoding Service. The geocode parameters restrict the address search to Japan.

// set geocode parameters to search within Japan
var geocodeParams = new GeocodeParameters
{
    CountryCode = "Japan",
    OutputLanguage = new System.Globalization.CultureInfo("ja-JP")
};


geocodeParams.ResultAttributeNames.Add("City");


// geocode the Japanese Prime Minister's office address
var matches = await _geocodeTask.GeocodeAsync("東京都千代田区永田町2‐2‐2", geocodeParams);


// get the top match (first one), return if none are found
// (add a using statement for System.Linq to enable syntax like the following)
var bestMatch = matches.FirstOrDefault();
if (bestMatch == null) { return; }

Japanese geocoding result
Note:

See Geocode coverage in the REST API documentation for a list of supported countries and corresponding codes.

Find points of interest

You can also geocode points of interest using a place name, such as Eiffel Tower or even more general terms, such as bank or bus stop. The geocode parameters allow you to restrict your search to a specified extent or to prefer candidates that are closer to a specified location, which can be useful if searching for facilities near the user's current position. You can provide the user with information about the locations, such as addresses, phone numbers, and URLs for candidates, as well as the distance from a reference location.

Tip:

Not all locators support geocoding a point of interest. The result information for candidates will also vary with the locator. Use LocatorInfo to see if geocoding points of interest is supported and which attributes are available for the result candidates, as described in a preceding section. The Distance attribute will only contain (non-zero) values if a preferred search location (point) is provided in the geocode parameters.

Geocoding a point of interest involves the same process as using an address described in the previous section. Instead of passing a single-line address value as input, you can provide a place name. The following are examples:

  • Point of interest by name
    • Wrigley Field
    • Disneyland
    • mount everest
  • Point of interest by category
    • restaurant
    • petrol
    • coffee in Salt Lake City
  • Administrative place name, such as a city/county/state/province/country name—Seattle, Washington
  • Postal code—92591 USA

You can use geocode parameters to refine or restrict search results when geocoding place names just as you do with addresses.

The following example searches for places in the category Ice Cream Shop near a specified location (the center of the map extent) and gets the name, phone number, address, and distance of the closest match.

// return if points of interest are not supported by this locator
if (!_geocodeTask.LocatorInfo.SupportsPoi) { return; }


// set geocode parameters to return a max of 5 candidates near the center of the current extent
var mapCenter = MyMapView.GetCurrentViewpoint(ViewpointType.CenterAndScale).TargetGeometry as MapPoint;
var geocodeParams = new GeocodeParameters
{
    MaxResults = 5,
    PreferredSearchLocation = mapCenter
};


// request address, phone, and distance as result attributes 
// (note: distance is only populated if a PreferredSearchLocation is set in the geocode parameters)
geocodeParams.ResultAttributeNames.Add("Place_addr");
geocodeParams.ResultAttributeNames.Add("Phone");
geocodeParams.ResultAttributeNames.Add("Distance");


// find candidates using a place category ("ice cream")
var matches = await _geocodeTask.GeocodeAsync("ice cream", geocodeParams);


if (matches.Count == 0) { return; }


// get information for the closest candidate
// (add a using statement for System.Linq to enable syntax like the following)
var closestMatch = (from m in matches orderby m.Attributes["Distance"] select m).FirstOrDefault();
var name = closestMatch.Label;
var address = closestMatch.Attributes["Place_addr"].ToString();
var phone = closestMatch.Attributes["Phone"].ToString();
var distance = (double)closestMatch.Attributes["Distance"];

Results of finding locations with the search term "ice cream"
Related topics