Sign up ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

I am trying to create a buffer around a point derived from a locator search, using this example: ..but I am getting no results. I am not sure how to pass the correct information from the locator result graphic to the buffer functions (sorry if this has been answered before, i couldn't find a solution).

Thanks, code is below..Jason

    ////////////// locator func ///////////////////////////////////

  function showLocatorResults(candidates) 
    var candidate;
    var symbol = new esri.symbol.SimpleMarkerSymbol();
    symbol.setColor(new dojo.Color([153, 0, 51, 0.75]));
    var geom, graphic;

    dojo.every(candidates, function (candidate) {

        if (candidate.score > 80) 
           // extent code removed for brevity
            var attributes = { address: candidate.address, score: candidate.score,    locatorName: candidate.attributes.Loc_name };
            geom = candidate.location;
            graphic = new esri.Graphic(geom, symbol, attributes);

            return false; 


     ////////// buffer funcs ////////////////////////////////////////////////
     function doBuffer(g) {

    bufferParams = new esri.tasks.BufferParameters();
    bufferParams.distances = [100];         
    bufferParams.geometries =  [g.geometry] ; // problem here?

    bufferParams.unit = esri.tasks.BufferParameters.UNIT_FOOT;
    bufferParams.outSpatialReference = map.spatialReference;
    geometrySvc.buffer (bufferParams, showBuffer);

function showBuffer(geometries) {

  var symbol = new esri.symbol.SimpleFillSymbol(
    new esri.symbol.SimpleLineSymbol(
      new dojo.Color([0,0,255,0.65]), 2
    new dojo.Color([0,0,255,0.35])

  dojo.forEach(geometries, function(geometry) {
    var graphic = new esri.Graphic(geometry,symbol);;

share|improve this question
I should add that I added the proxy page code in my init function, also taken from ESRI examples: //identify proxy page to use if the toJson payload to the geometry service is greater than 2000 characters. //If this null or not available the buffer operation will not work. Otherwise it will do a http post to the proxy. = "/arcgisserver/apis/javascript/proxy/proxy.ashx"; = false; – JasonBK Oct 3 '12 at 17:42

1 Answer 1

Here's a working example that geocodes and address/place and then buffers the first result:

<!doctype html>
<html lang="en">
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=7,IE=9" />
    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no"/>
    <link rel="stylesheet" type="text/css" href="" />
    <link rel="stylesheet" type="text/css" href="" />

      html, body { height: 100%; width: 100%; margin: 0; padding: 0; }
      h3 { margin: 0 0 5px 0; border-bottom: 1px solid #444; }
      .shadow {
        -moz-box-shadow: 0 0 5px #888;
        -webkit-box-shadow: 0 0 5px #888;
        box-shadow: 0 0 5px #888;
      #map{ margin: 0; padding: 0; }
      #feedback {
        background: #fff;
        bottom: 30px;
        color: #444;
        position: absolute;
        font-family: arial;
        height: 80px;
        left: 30px;
        margin: 5px;
        padding: 10px;
        width: 300px;
        z-index: 40;
    <script>var dojoConfig = { parseOnLoad: true };</script>
    <script src=""></script>

      var map, locator;
      function init() {
        // why write a lot of javascript code when you can use to author your webmap?
        var webmapId = "8ca10201ec3d4c2a8e2e628df59c8c54";

        //create map
        var mapDeferred = esri.arcgis.utils.createMap(webmapId, "map", {
          mapOptions: { slider: false }

        locator = new esri.tasks.Locator("");

        dojo.connect(dijit.byId("locate"), "onClick", function() {
          var address = dojo.byId("address").value;
          console.log("address: ", address);
          if ( ! address ) {
            alert("Please enter an address to geocode.");
          locator.outSpatialReference = map.spatialReference;
          var geocode = locator.addressToLocations({
            address: { "SingleLine": address },
            outFields: ["*"]

          geocode.then(function(results) {
            console.log("got results: ", results);
            // add the results to the map
            dojo.forEach(results, function(r) {
                r.location, new esri.symbol.SimpleMarkerSymbol(), r.attributes
            console.log("added buffer the first one");
          }, function(error) {
            console.log("geocode failed: ", error);

        mapDeferred.addCallback(function (response) {
          map =;
          dojo.connect(dijit.byId("map"), "resize", map, map.resize);

      function bufferLocation(place) {
        var bufferParams = new esri.tasks.BufferParameters();
        bufferParams.geometries = [ place.location ];
        bufferParams.distances = [ 5 ]; // 5 km
        bufferParams.outSpatialReference = map.spatialReference;
        bufferParams.unit = esri.tasks.GeometryService.UNIT_KILOMETER;

        var gs = new esri.tasks.GeometryService("");
        var buffer = gs.buffer(bufferParams);
        buffer.then(function(buffers) {
          console.log("got buffers: ", buffers);
          dojo.forEach(buffers, function(b) {
              b, new esri.symbol.SimpleFillSymbol()
        }, function(error) {
          console.log("error doing buffer...", error);

  <body class="tundra">
    <div data-dojo-type="dijit.layout.BorderContainer"
         style="width: 100%; height: 100%; margin: 0;">
      <div id="map"

        <div id="feedback" class="shadow">
          <h3>Locate and address then buffer.</h3>
          <div id="info">
            <input type="text" id="address" value="Wrigley Field">
            <button dojotype="dijit.form.Button" id="locate">Locate</button> 

Note that no proxy is used. If you're buffering a single point, a proxy isn't necessary as the URL that's generated isn't likely to be > 2k characters. If you're buffering many points, or large line or polygon geometries then you'd need a proxy.

Another point to stress is that you should ask for results from the locator in the spatial reference of your map. This is done with the following line of code:

locator.outSpatialReference = map.spatialReference;
share|improve this answer
OK thanks for far I haven't had any luck following your example. I tried 'candidates[0]' as a parameter but no buffer is drawn (my code does work when I substitute a map click as an event parameter) difference I see is that you are using v3.2 of the API, but I am restricted currently to v2.1...and the locator method signature is slightly different. COuld this be part of my problem (see link…) ... Thanks, J – JasonBK Oct 9 '12 at 14:34
sorry, forgot to add my locator function: function locate() {; var address = { "SingleLine": dojo.byId("address").value }; locator.outSpatialReference = map.spatialReference; locator.addressToLocations(address);} /// also, I am trying to use the buffer for a query, and I seem to be limited to 400 ft. Greater than this, and no buffer draws on the screen. Is this related to the proxy page perhaps? – JasonBK Oct 9 '12 at 18:36
Hello, just checking in about this, I still haven't found a guess is that there is some incompatibility with v2.1 of the API, and that I may need a proxy page b/c I am using the buffer for a query..any help is appreciated, thanks! – JasonBK Oct 15 '12 at 13:06
@JasonBK I haven't looked at this since I originally posted my answer. As far as I know, the proxy requirements haven't changed. Please do consider upgrading as it's a simple process and 2.1 is over two years old. For this specific issue, if you can provide a complete working example that reproduces the problem then I might be able to provide more help. – Derek Swingley Oct 15 '12 at 15:14
thanks..I am working on upgrading but I need to rewrite some of the code, including changing a ComboBox to a FilteringSelect, as the ComboBox does not seem to work with more current API versions...I may start another thread about this; so far I haven't got this switch to work... – JasonBK Oct 15 '12 at 19:30

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.