Skip To Content ArcGIS for Developers Sign In Dashboard


You will learn: how to build an app to find addresses and places with the ArcGIS World Geocoding Service.

With the ArcGIS Runtime SDK for iOS you can easily find places and addresses all around the world. The process of matching locations or place names on the map to an address is referred to as geocoding. Your user can specify a location of interest or street address and see it on the map. You can use the ArcGIS World Geocoding Service as a locator which has the ability to search for places, business names and addresses, and supports many different input formats. You can also perform reverse geocoding where you pass in a point location or latitude and longitude and the locator will return the address it finds. With this functionality you can build powerful apps that allow users to easily find what they are looking for.

Locating addresses is a service with many features and options. Refer to Search for places (geocoding) if you would like to read more about the process and options.

This tutorial is a bit complex because you will define a user interface to handle user interaction. This demonstrates one of many possible methods for requesting user input. The method used here places the search bar at the top of the iOS device's screen.

Before you begin

Make sure you have installed the latest version of Xcode.

Reuse the starter project

If you have completed the Create a starter app tutorial, then copy the project into a new empty folder. Otherwise, download and unzip the project solution. Open the .xcodeproj file in Xcode. Run and verify the map displays in the device simulator.


Add a Search Bar to the app

  1. In the project navigator, find the Main.storyboard file. Add a Search Bar above the Map View (if you prefer to start with the UI already wired up, use this project and skip ahead to Search for an address below.).

    Add a search bar

  2. Right-click on the Search Bar and drag the delegate outlet to the View Controller.

  3. In the project navigator, find the ViewController.swift file. Update the class definition to specify that it implements the UISearchBarDelegate protocol.

    class ViewController: UIViewController, UISearchBarDelegate {

Search for an address

  1. Create an AGSLocatorTask instance variable pointing to the ArcGIS Online World Geocoder Service.

        @IBOutlet weak var mapView: AGSMapView!
        /* ADD */
        let geocoder:AGSLocatorTask = AGSLocatorTask(url: URL(string: "")!)
  2. Add a searchBarSearchButtonClicked handler for UISearchBarDelegate to search for the user's request entered in the Search Bar. Call the geocoder's geocode() method with the search text. Handle the response by taking the first result and zooming the map to that location.

     func searchBarSearchButtonClicked(_ searchBar: UISearchBar) {
         guard let searchText = searchBar.text, !searchText.isEmpty else {
             print("Nothing to search!")
         geocoder.geocode(withSearchText: searchText) { (results, error) in
             guard error == nil else {
                 print("Error geocoding '\(searchText)': \(error!.localizedDescription)")
             guard let firstResult = results?.first, let extent = firstResult.extent else {
                 let alert = UIAlertController(title: "Nothing found",
                                               message: "No results found for \(searchText)",
                                               preferredStyle: .alert)
                 alert.addAction(UIAlertAction(title: "Ok", style: UIAlertActionStyle.default, handler: { _ in
                     alert.dismiss(animated: true)
                 self.present(alert, animated: true)
  3. Press Command-R to run the app in the iOS Simulator.

Congratulations, you're done!

The map should load and display a search bar at the top. Enter some text in the search bar and press enter. The map will zoom to the first geocoded result. Compare your solution with our completed solution project.


Show a graphic

The map zooms to the search result, but there is nothing placed on the map to show the actual location. Try using the search result's displayLocation property to create a point-based AGSGraphic to display on the map. You will need to add an AGSGraphicsOverlay to the mapView to display the graphic.

Multiple results

The geocode() method has a version that takes additional parameters. Try using AGSGeocodeParameters and varying setMaxResults to show the user multiple possible matches. Can you come up with a UI that allows the user to select a possible match?

Geocoding parameters

Can you discover other geocoding parameters available to the locator task? For example, limit the search area to the visible extent of the map view.

Show suggestions

The ArcGIS Online geocoder includes functionality to return suggestions for a partially-typed search string. See if you can come up with a UI to present suggestions to the user as they type in the search bar. Investigate the AGSGeocoder.suggest() methods to get AGSSuggestResults. You then pass the selected suggestion to the AGSLocatorTask. This Open Source App might provide some inspiration.