esri.tasks.locator

1033
8
04-02-2012 09:57 AM
RashaGarfinkel
New Contributor
If I want to be able to locate and zoom to a county on the map - would that work with locator.addressToLocations()
Currently I use addressToLocations(address) in which the adress contains address, city, state and zip - but I just want to locate based on county and state?

Thanks
0 Kudos
8 Replies
derekswingley1
Frequent Contributor
Depends on how the underlying locator works. For what you're describing, you can use esri.tasks.Locator to hit this service:  http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/ESRI_Places_World/GeocodeServer
0 Kudos
RashaGarfinkel
New Contributor
Thanks for your reply - I am currently using that but when I try just specifiying a county & state no value comes back, but when I put in the whole adress - all these fields:
var address = {
                                                    address : "",
                                                    city: "",
                                                    county: "",
                                                    state: "",
                                                    zZip: ""
                                              };
then I get a value back.
How can I get a value back by just entering some of these fileds?
0 Kudos
derekswingley1
Frequent Contributor
0 Kudos
RashaGarfinkel
New Contributor
still stuck on this because I only want to pass in county & state -
here's my code that pulls the data from the controls:
var address = {
                                                     county: "",
                                                    state: ""
                                                                                                  };
    dojo.forEach(this.locatorFields, dojo.hitch(this, function(name) {
     address[name] = this.widgets[name].getValue();
                                         }));
                                
                              
    this.locator.addressToLocations(address);
no results are coming back even though I know ocean, nj exists - any ideas? do I need a list of predefined counties in each state?
0 Kudos
HemingZhu
Occasional Contributor III
still stuck on this because I only want to pass in county & state -
here's my code that pulls the data from the controls:
var address = {
                                                     county: "",
                                                    state: ""
                                                                                                  };
    dojo.forEach(this.locatorFields, dojo.hitch(this, function(name) {
     address[name] = this.widgets[name].getValue();
                                         }));
                                
                              
    this.locator.addressToLocations(address);
no results are coming back even though I know ocean, nj exists - any ideas? do I need a list of predefined counties in each state?


Try this:
var address ={}; Then specify any address fields that have value. for example, if address and state has value (ocear, nj), then your code should be: address.address ="ocean"; address.state ="nj";
0 Kudos
RashaGarfinkel
New Contributor
thanks, I tried that & getting back 0 locations, I try just setting NJ for state also nothing - am I using the correct arcGis location:
http://tasks.arcgisonline.com/ArcGIS/rest/services/Locators/TA_Address_NA/GeocodeServer
0 Kudos
RashaGarfinkel
New Contributor
I am not sure what I am doing wrong but when I only want to specify a county and state as the address locator - no results come back - can someone please provide me with some guidance on how to use this api correctly.
my javascript so far:
var address = {
                                  county: "Ocean",
                                  state: "NJ"

                      };
this.locator.addressToLocations(address);
It works fine when I use  all the specific address variables like this:
var address = {
                                                   address : "",
                                                   city: "",
                                                   state: "",
                                                   zZip: ""
                                              };
    dojo.forEach(this.locatorFields, dojo.hitch(this, function(name) {
     address[name] = this.widgets[name].getValue();
    }));

Thanks for your continued help
0 Kudos
HemingZhu
Occasional Contributor III
I am not sure what I am doing wrong but when I only want to specify a county and state as the address locator - no results come back - can someone please provide me with some guidance on how to use this api correctly.
my javascript so far:
var address = {
                                  county: "Ocean",
                                  state: "NJ"

                      };
this.locator.addressToLocations(address);
It works fine when I use  all the specific address variables like this:
var address = {
                                                   address : "",
                                                   city: "",
                                                   state: "",
                                                   zZip: ""
                                              };
    dojo.forEach(this.locatorFields, dojo.hitch(this, function(name) {
     address[name] = this.widgets[name].getValue();
    }));

Thanks for your continued help


I think the better approach would be to create your own simple locator that has city and state as your address fields. You could easily grab a state and county layer and build and locator on it.
0 Kudos