Select to view content in your preferred language

What is wrong with my syntax?

3977
12
Jump to solution
07-17-2015 08:38 AM
ChrisSergent
Deactivated User

I want to use the findAddress Candidates, but I am receiving a syntax error. What do I need to modify?

<script>
         require(["esri/tasks/AddressCandidate",
                   "dojo/_base/array"], function (AddressCandidate,array) {
                       on(dom.byId("btnTest"),"click",function() {
                           array.forEach(addressCandidates, function(candidate) {
                               if (candidate.score > score && candidate.attributes.Loc_name === document.getElementById("ownerAddress").value) {
                                   stop = candidate;
                                   score = candidate.score;
                                   // Display the score on the console.
                                   console.log = score;
                               }
                           })
                    });
                           
                                   
     </script>

And the AddressCandidate code sample appear to be incomplete. What else do I need besides what they show. I figure my addressLocator; anything else?

Here is my updated code: csergent45/codeViolationNotice at 3cd51e07008dfb3882231ba9f252d81dbef05bae · GitHub

0 Kudos
1 Solution

Accepted Solutions
JoelBennett
MVP Regular Contributor

You're missing an additional "});" at the end.  The following is syntactically correct:

require(["esri/tasks/AddressCandidate", "dojo/_base/array"], function (AddressCandidate,array) {  
 on(dom.byId("btnTest"),"click",function() {  
  array.forEach(addressCandidates, function(candidate) {  
   if (candidate.score > score && candidate.attributes.Loc_name === document.getElementById("ownerAddress").value) {  
    stop = candidate;  
    score = candidate.score;  
    // Display the score on the console.  
    console.log(score);
   }  
  });
 });
});

I recommend you bookmark this page: The Online Lint  - I use it many times per day.

View solution in original post

12 Replies
by Anonymous User
Not applicable

Huh I've never seen console.log with '=', just console.log()

ChrisSergent
Deactivated User

That was a mistake. I know better than to write assignment statements.

0 Kudos
KenBuja
MVP Esteemed Contributor

What is the syntax error that you're receiving? Where are you setting the variable score? The first time you run through the candidates in the foreach, is "candidate.score > score" getting evaluated properly?

ChrisSergent
Deactivated User

It's in my prans and curly braces. I don't have it set right.

0 Kudos
ReneRubalcava
Honored Contributor

Yeah, don't do console.log = anything, you overwrite it and can just break the internet like that.

But on your original question, where the addressCandidates array coming from?

I think what you are trying to do is use the Locator Task.

ChrisSergent
Deactivated User

If I reference the Locator Task, will I be able to use find Address Candidates? Say you owned every house on your block and had to enter each address on each line on an online form. I have to verify that each one of those addresses is correct or close. That's why I am trying to use Address Candidates.

But I am getting a syntax error from my code. Ignore the console.log line. I was in a rush, but there is a syntax error without that line. Any idea what it is?

I want to figure that out before I add more code.

0 Kudos
ReneRubalcava
Honored Contributor

Probably because addressCandidates is null. AddressCandidate is the data type for what is returned from a Locator, it doesn't do anything.

This is what you want

Locator | API Reference | ArcGIS API for JavaScript

0 Kudos
JoelBennett
MVP Regular Contributor

You're missing an additional "});" at the end.  The following is syntactically correct:

require(["esri/tasks/AddressCandidate", "dojo/_base/array"], function (AddressCandidate,array) {  
 on(dom.byId("btnTest"),"click",function() {  
  array.forEach(addressCandidates, function(candidate) {  
   if (candidate.score > score && candidate.attributes.Loc_name === document.getElementById("ownerAddress").value) {  
    stop = candidate;  
    score = candidate.score;  
    // Display the score on the console.  
    console.log(score);
   }  
  });
 });
});

I recommend you bookmark this page: The Online Lint  - I use it many times per day.

ChrisSergent
Deactivated User

Thanks. I bookmarked that. I still had a little bit of trouble following it, but at least it gives tips.

0 Kudos