Here's a working example that geocodes and address/place and then buffers the first result:
<!doctype html>
<html lang="en">
<head>
<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"/>
<title></title>
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/dojo/dijit/themes/tundra/tundra.css" />
<link rel="stylesheet" type="text/css" href="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/js/esri/css/esri.css" />
<style>
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;
}
</style>
<script>var dojoConfig = { parseOnLoad: true };</script>
<script src="http://serverapi.arcgisonline.com/jsapi/arcgis/3.2/"></script>
<script>
dojo.require("dijit.layout.BorderContainer");
dojo.require("dijit.layout.ContentPane");
dojo.require("dijit.form.Button");
dojo.require("esri.arcgis.utils");
dojo.require("esri.map");
dojo.require("esri.tasks.locator");
var map, locator;
function init() {
// why write a lot of javascript code when you can use arcgis.com 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("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
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.");
return;
}
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) {
map.graphics.add(new esri.Graphic(
r.location, new esri.symbol.SimpleMarkerSymbol(), r.attributes
));
});
console.log("added graphics...now buffer the first one");
bufferLocation(results[0]);
}, function(error) {
console.log("geocode failed: ", error);
});
});
mapDeferred.addCallback(function (response) {
map = 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("http://sampleserver6.arcgisonline.com/arcgis/rest/services/Utilities/Geometry/GeometryServer");
var buffer = gs.buffer(bufferParams);
buffer.then(function(buffers) {
console.log("got buffers: ", buffers);
dojo.forEach(buffers, function(b) {
map.graphics.add(new esri.Graphic(
b, new esri.symbol.SimpleFillSymbol()
));
});
}, function(error) {
console.log("error doing buffer...", error);
});
}
dojo.ready(init);
</script>
</head>
<body class="tundra">
<div data-dojo-type="dijit.layout.BorderContainer"
data-dojo-props="design:'headline',gutters:false"
style="width: 100%; height: 100%; margin: 0;">
<div id="map"
data-dojo-type="dijit.layout.ContentPane"
data-dojo-props="region:'center'">
<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>
</div>
</div>
</div>
</div>
</body>
</html>
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;