AnsweredAssumed Answered

catch no result in custom geocoder

Question asked by faymtownsend on May 8, 2014
Latest reply on May 9, 2014 by faymtownsend
I'm new to the Javascript API but not new to Javascript, but maybe rusty admittedly.

I'm having a hard time figuring out how to catch when a custom geocoder does not return an address for entered search.

Example coded below.

Search for "hay" and the display div is populated with the returned name "Hay street". if you search for "super street" , which returns nothing. I would want it display "no information"


Anyone able to guide me in the right direction.


<!DOCTYPE html> <html>   <head>     <meta http-equiv="Content-Type" content="text/html; charset=utf-8">     <meta http-equiv="X-UA-Compatible" content="IE=edge">     <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no">     <title></title>          <link rel="stylesheet" href="http://js.arcgis.com/3.9/js/esri/css/esri.css">     <style>       html, body, #map {         height: 100%;         width: 100%;         margin: 0;         padding: 0;       }       #search {         display: block;         position: absolute;         z-index: 3;         top: 20px;         left: 75px;       }       #display {        padding-top:200px;       }     </style>          <script src="http://js.arcgis.com/3.9/"></script>     <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>     <script>       require([         "esri/map",         "esri/dijit/Geocoder",          "dojo/dom",         "dojo/domReady!"       ], function(         Map, Geocoder,         dom       ) {          // create a map and instance of the geocoder widget here         var myGeocoders = [{           url: "http://gis.ci.fayetteville.nc.us/arcgis/rest/services/Composite_Locator/GeocodeServer",           name: "Composite_Locator",           singleLineFieldName: "Street"         }];                              var geocoder =  new Geocoder({           autoComplete: true,           arcgisGeocoder: false,           geocoders: myGeocoders         }, dom.byId("search"));        //  map.on("load", enableSpotlight);          geocoder.on("select", showLocation);       //  geocoder.on("clear", removeSpotlight);          function showLocation(evt) {         // console.log(evt)           $('#display').append(evt.result.name);         //  console.log(evt.result.name)         }        });     </script>   </head>   <body class="soria">     <div id="search"></div>     <div id="display"></div>               </body>  </html>

Outcomes