Overview

You will learn: how to find the latitude and longitude of an address using the ArcGIS World Geocoding Service.

The ArcGIS World Geocoding Service can find addresses, places, convert addresses to coordinates, and perform batch geocoding. If you would like to create an application that can find the coordinates (latitude and longitude) for one or more addresses, you can use the ArcGIS REST API to call the findAddressCandidates operation. All you need to do is pass in an address e.g. "380 New York St., Redlands, CA" and the service will return a set of candidates. Once you have candidates, you can add them to a map, create a route, or integrate them further into your application. You can also geocode many addresses at once with the geocodeAddresses operation. To learn more about the capabilities of the geocoding service, please visit the documentation.

In this lab you will use the ArcGIS REST API to access the ArcGIS World Geocoding Service to find the coordinates for an address.

Before you begin

Install Postman to execute HTTP requests. Go to this lab if you need an access token.

Steps

Create a request to access the geocoding service

  1. Open Postman and click [+] in the tab bar to create a new request.

  2. In the new tab, set the following:

    • HTTP Method: GET
    • Request URL: https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer/findAddressCandidates

Add parameters to define the address and data fields to return

  1. Click on Params next to the URL and the following:

    • f: json
    • singleLine: 4730 Crystal Springs Dr, Los Angeles, CA 90027
    • outFields: Match_addr,Addr_type

Execute the request to geocode the address and get the coordinate candidates

  1. Click Send to run the request.

  2. In the response window, change the view to JSON and it should look something like this:

    {
        "spatialReference": {
            "wkid": 4326,
            "latestWkid": 4326
        },
        "candidates": [
            {
                "address": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
                "location": {
                    "x": -118.27393677823306,
                    "y": 34.123473000000004
                },
                "score": 100,
                "attributes": {
                    "Match_addr": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
                    "Addr_type": "PointAddress"
                },
                "extent": {
                    "xmin": -118.27486,
                    "ymin": 34.122473000000006,
                    "xmax": -118.27285999999999,
                    "ymax": 34.124473000000002
                }
            },
            {
                "address": "4730 Crystal Springs Rd, Los Angeles, California, 90027",
                "location": {
                    "x": -118.29234632205821,
                    "y": 34.140621986664307
                },
                "score": 98.040000000000006,
                "attributes": {
                    "Match_addr": "4730 Crystal Springs Rd, Los Angeles, California, 90027",
                    "Addr_type": "StreetAddress"
                },
                "extent": {
                    "xmin": -118.29334632205821,
                    "ymin": 34.139621986664309,
                    "xmax": -118.2913463220582,
                    "ymax": 34.141621986664305
                }
            }
        ]
    }
    
  3. Go to the top of the response and find the spatialReference and candidates properties. The spatialReference is 4326 and tells you that the coordinates given in candidates will be latitude/longitude coordinates (y/x). This is the default spatial reference.

    {
        "spatialReference": {
            "wkid": 4326,
            "latestWkid": 4326
        },
    ...
    
  4. Find the candidates property. This is an array of possible matches for the address. Each match consists of:

    • address: The address of this match.
    • location: The x/y coordinates of this match. Note that x is longitude and y is latitude.
    • score: The confidence level of the geocoder in this match, on a scale of 1-100.
    • attributes: Any additional fields requested by the outFields parameter.
    • extent: a rectangular bounding box around the location given as a pair of x/y coordinates.
     "candidates": [
         {
             "address": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
             "location": {
                 "x": -118.27393677823306,
                 "y": 34.123473000000004
             },
             "score": 100,
             "attributes": {
                 "Match_addr": "4730 Crystal Springs Dr, Los Angeles, California, 90027",
                 "Addr_type": "PointAddress"
             },
             "extent": {
                 "xmin": -118.27486,
                 "ymin": 34.122473000000006,
                 "xmax": -118.27285999999999,
                 "ymax": 34.124473000000002
             }
         },
       ...
    

  1. In Postman click Code below the Send button. Select a programming language and use Postman to generate sample code for your application to run this request.

Congratulations, you're done!

You have successfully found a set of candidates with coordinates for an address.

Challenge

Use geocoding suggestions

You can use the Esri World Geocoding Service to build an auto-completing, suggestion-based UX by adding a special parameter called magicKey to findAddressCandidates instead of an address. To obtain a value for magicKey, refer to the documentation for the suggest endpoint.

Try bulk geocoding

If you need to geocode many addresses in bulk, you can use the geocode addresses endpoint.

Find latitude/longitude of intersections

findAddressCandidates can also return the coordinates of intersections if the address is in the proper format. For more information, see searching for intersections and try changing the value of singleLine to "Griffith Park Dr. and Crystal Springs Dr, Los Angeles, CA"