Geocoder - how to go to value at startup?

586
2
Jump to solution
07-28-2014 02:29 PM
LauraLance
New Contributor

I am specifying a value for input textbox of the geocoder. It is a field (geoPlace) that is calculated. It fills in the textbox just fine. I would like for it to then automatically zoom to that place at startup. Is there a way to do this? It seems like I should use geocoder.find() but I haven't been successful.

    geocoder = new Geocoder({

        map: map,

        value: geoPlace

    }, "search");

    geocoder.startup();

Tags (1)
0 Kudos
1 Solution

Accepted Solutions
OwenEarley
Occasional Contributor III

Hi Laura,

Check out the Geocode an address | ArcGIS API for JavaScript‌ sample. This sample geocodes an address then zooms to the location.

You should be able to insert your geoPlace variable into the locate function - something like:


function locate() {
          map.graphics.clear();
          var address = {
            "SingleLine": geoPlace
          };
          locator.outSpatialReference = map.spatialReference;
          var options = {
            address: address,
            outFields: ["Loc_name"]
          }
          locator.addressToLocations(options);
}

Hope this helps,

Owen

www.spatialxp.com.au

View solution in original post

0 Kudos
2 Replies
OwenEarley
Occasional Contributor III

Hi Laura,

Check out the Geocode an address | ArcGIS API for JavaScript‌ sample. This sample geocodes an address then zooms to the location.

You should be able to insert your geoPlace variable into the locate function - something like:


function locate() {
          map.graphics.clear();
          var address = {
            "SingleLine": geoPlace
          };
          locator.outSpatialReference = map.spatialReference;
          var options = {
            address: address,
            outFields: ["Loc_name"]
          }
          locator.addressToLocations(options);
}

Hope this helps,

Owen

www.spatialxp.com.au

0 Kudos
LauraLance
New Contributor

Thank you! This is exactly what I needed.

0 Kudos