I was modifying one example script from online ESRI's resource. Changed the projection information, basemap url, locator url. For some reason the "Locate" button always returns to a point, instead of an extent area. I am very new in js, please kindly help me.
function init() { var initExtent = new esri.geometry.Extent({"xmin":-180,"ymin":-90,"xmax":180,"ymax":90,"spatialReference":{"wkid":4326}}); map = new esri.Map("map",{ wrapAround180:true, extent:initExtent }); //resize map when browser size changes dojo.connect(map, 'onLoad', function(theMap) { var resizeTimer; dojo.connect(dijit.byId('map'), 'resize', function() { //resize the map if the div is resized clearTimeout(resizeTimer); console.log('resize'); resizeTimer = setTimeout( function() { map.resize(); map.reposition(); }, 500); }); }); var basemap = new esri.layers.ArcGISTiledMapServiceLayer("http://data.nodc.noaa.gov/arcgis/rest/services/NODC-Ocean-Basemap-version-2012-01-24/MapServer"); map.addLayer(basemap);
//Draw and zoom to the result when the geocoding is complete dojo.connect(locator, "onAddressToLocationsComplete", function(geocodeResults) { map.graphics.clear(); dojo.forEach(geocodeResults, function(geocodeResult, index) { //create a random color for the text and marker symbol var r = Math.floor(Math.random() * 250); var g = Math.floor(Math.random() * 100); var b = Math.floor(Math.random() * 100); var symbol = new esri.symbol.SimpleMarkerSymbol(esri.symbol.SimpleMarkerSymbol.STYLE_CIRCLE, 20, new esri.symbol.SimpleLineSymbol(esri.symbol.SimpleLineSymbol.STYLE_SOLID, new dojo.Color([r, g, b, 0.5]), 10), new dojo.Color([r, g, b, 0.9])); var pointMeters = esri.geometry.Polygon(geocodeResult.location); var locationGraphic = new esri.Graphic(pointMeters, symbol); var font = new esri.symbol.Font().setSize("12pt").setWeight(esri.symbol.Font.WEIGHT_BOLD); var textSymbol = new esri.symbol.TextSymbol((index + 1) + ".) " + geocodeResult.address, font, new dojo.Color([r, g, b, 0.8])).setOffset(5, 15); //add the location graphic and text with the address to the map map.graphics.add(locationGraphic); map.graphics.add(new esri.Graphic(pointMeters, textSymbol)); }); var ptAttr = geocodeResults[0].attributes; var esriExtent = new esri.geometry.Extent(ptAttr.West_Lon, ptAttr.South_Lat, ptAttr.East_Lon, ptAttr.North_Lat, new esri.SpatialReference({wkid: 4326})); map.setExtent(esri.geometry.Polygon(esriExtent));
//Perform the geocode. This function runs when the "Locate" button is pushed. function locate() { var address = { 'SingleLine': dojo.byId("address").value }; //optionally return the out fields if you need to calculate the extent of the geocoded point locator.addressToLocations(address,["*"]); }