Automate the process of zooming into the first returned geocoded result (HTML Viewer)


You can have the Locate Address tool automatically zoom in to the first returned geocoded result by doing a few simple edits to your HTML Viewer's aimsGeocode.js file, as described below. The first result will always be the result with the highest score. This article also illustrates how to zoom in on the geocode result only if one result is returned.


  1. Open the HTML Viewer's aimsGeocode.js file in a text editor.

  2. Find the following block of code at the very end of the file:

    if (GCpointCount==1) sendMapXML();
    //if (GCpointCount==1) zoomToPoint(GCpointX[0], GCpointY[0], true, geocodeLabel);

    This should take you to the bottom of the parseGeocodeResults function, which is responsible for parsing the ArcXML geocode response from the spatial server.

  3. Replace the above block of code with the following:

    //if (GCpointCount==1) sendMapXML();
    var gcptx = parseFloat(GCpointX[0]);
    var gcpty = parseFloat(GCpointY[0]);
    //if (GCpointCount==1) zoomToPoint(gcptx, gcpty, true, geocodeLabel);
    zoomToPoint(gcptx, gcpty, true, geocodeLabel);

    This will result in the map automatically zooming to the first geocode result returned. The zoomToPoint function is already set up to do this.

  4. Comment out the following blocks if you want to zoom only when one result is returned:

    if (GCpointCount==1) zoomToPoint(gcptx, gcpty, true, geocodeLabel);

    zoomToPoint(gcptx, gcpty, true, geocodeLabel);

    Two forward slashes (//) are the comment characters in Java Script.

  5. Save the file.
  6. Quit and restart your browser.

Article ID:000003000

  • Legacy Products

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options

Related Information

Discover more on this topic