AnsweredAssumed Answered

ESRI JavaScript API 3.8 Locator: SyntaxError {log: undefined, stack: (…), message: “Unexpected token <”}

Question asked by bwcoleman18_1 on Jul 10, 2014
Latest reply on Jul 14, 2014 by bwcoleman18_1

I am having issues trying to set up a geocoder/locator on my server and also trying to query my geometry service when trying to project some lat/long coordinated. I keep getting an error SyntaxError {log: undefined, stack: (...), message: "Unexpected token <"}, but I can't seem to figure out why. I tried exploring the error message, but I don't get much good information out of it.

I have tried using ESRI's geocoder widget then created my own set up using the locator service. I have checked my address string, and I believe it should be passing correctly over to the server.

If I am understanding the error message right, it is saying there is a token "<" somewhere that shouldn't be there, but I cannot find it.

Other info... I am running version 9.3.1 for my server, using the JavaScript API 3.8 that ESRI hosts, and created an address locator on my server using street centerlines for the area I am mapping.

Has anyone run into this issue before or have suggestions for me? Right now, I am just trying to center the map on the location. Once I get that done, I can worry about all the other stuff.

My code for the locator is below.  The site I am working on is at: Louisville Urban Tree Canopy Analysis

 

 /////////////////////////////////////////////////////////////////
locator = new Locator(singleFieldGeocodeURL);
//add handler for completion
locator.on("address-to-locations-complete", showResults);

//trying to find the error
locator.on("error", function (error) {
  errorObject = error;
  console.log("error" + error);

});


//add handler for button click
on(dom.byId('locate'), 'click', function () {

  console.log(dom.byId('address').value);

  map.graphics.clear();
  var address = {
  "SingleLine": dom.byId('address').value
  };

  locator.outSpatialReference = map.spatialReference;

  var options = {
  address: { street: address },
  outFields: ["Loc_name"]

  };
  locator.addressToLocations(options);

});

function showResults(evt) {
  console.log("in show results");
  var candidate;
  var symbol = new SimpleMarkerSymbol();
  symbol.setStyle(SimpleMarkerSymbol.STYLE_SQUARE);
  symbol.setColor(new Color([153, 0, 51, 0.75]));

  var geom;
  arrayUtils.event(evt.addresses, function (candidate) {
  console.log(candidate.score);
  if (candidate.score > 80) {
  console.log(candidate.location);
  var attributes = {
  address: candidate.address,
  score: candidate.score,
  locatorName: candidate.attributes.Loc_name
  };
  geom = candidate.location;
  var graphic = new Graphic(geom, symbol, attributes, null);
  map.graphics.add(graphic);

  return false;

  }
  });

  if (geom !== undefined) {
  map.centerAndZoom(geom, 12);
  }

}

Outcomes