Did you get this figured out yet? I got stuck in the same place, trying to sort out points vs. geometry etc. Not only did I want to enter an address, I still wanted my identifytask to work too.I created a couple of variablesvar geometryPt;
var idFromClick = true;
Your identify parameters are not anything different. For me I added an onClick event on the map. This gave me a place to call an identifyTask function that would work both from a click and from the results function of the locate. dojo.connect(map, "onClick", function () {idFromClick = true;});
dojo.connect(map, "onClick", executeIdentifyTask);
This is my executeIdentifyTask function. My identify was likely to return from multiple layers, so you'll need the same deferred technique if you do too. You need to pay attention to what sort of geometry you are using in your identifyparameters. When I call it from a click event, I needed to convert it to a mapPoint because it's only coordinates/geometry. When you get the results of a locator, it's already a point, so you need to keep track of whether a click or a geocode is the input. function executeIdentifyTask(evt) {
identifyParams.mapExtent = map.extent.expand(0.1);
identifyParams.geometry = evt;
var inputPt = evt;
if (idFromClick) { // input from map click
identifyParams.geometry = evt.mapPoint;
inputPt = evt.mapPoint;
}
var deferred = identifyTask.execute(identifyParams);
deferred.addCallback(function(response) {
// response is an array of identify result objects
// Let's return an array of features.
return dojo.map(response, function(result) {
var feature = result.feature;
feature.setInfoTemplate(myTemplate);
return feature;
});
});
// InfoWindow expects an array of features from each deferred object that you pass. If the response from the task execution
// above is not an array of features, then you need to add a callback like the one above to post-process the response and return an
// array of features.
map.infoWindow.setFeatures([ deferred ]);
map.infoWindow.resize(175,100);
map.infoWindow.show(inputPt); //point type is the same coming from either method
//map.infoWindow.show(evt.mapPoint);
}
Then make a few modifications to the standard locate and showResults functions. You can edit out the lines I have for "containsCounty". I'm mapping a whole state and I needed to handle somehow a user entering "Jackson County, MO" or some other county name instead of a city. function locate() { You can see at the very end I'm using the geocoded point as the input to the identify.
idFromClick = false; //executeIdentifyTask handles the type of point being passed.
map.infoWindow.hide();
map.graphics.clear();
geometryPt = "";
var address = {"SingleLine":dojo.byId("txtAddress").value};
locator.outSpatialReference= map.spatialReference;
var options = {
address:address,
outFields:["Loc_name"]
};
locator.addressToLocations(options);
}
function showResults(candidates) {
var candidate;
var symbol = new esri.symbol.SimpleMarkerSymbol();
var addressTemplate = new esri.InfoTemplate("Location", "Address: ${address}<br />");
symbol.setStyle(esri.symbol.SimpleMarkerSymbol.STYLE_SQUARE);
symbol.setColor(new dojo.Color([255,0,0,0.75]));
dojo.every(candidates,function(candidate){
console.log(candidate.score);
if (candidate.score > 80) {
console.log(candidate.location);
var attributes = { address: candidate.address, score:candidate.score, pt:candidate.location };
geometryPt = candidate.location;
var graphic = new esri.Graphic(geometryPt, symbol, attributes, addressTemplate);
//add a graphic to the map at the geocoded location
map.graphics.add(graphic);
//add a text symbol to the map listing the location of the matched address.
var displayText = candidate.address;
map.infoWindow.show(geometryPt);
map.infoWindow.setTitle("Address");
return false; //break out of loop after one candidate with score greater than 80 is found.
}
});
if(geometryPt !== undefined){
var containsCountyPosition = (dojo.byId("txtAddress").value.toLowerCase().indexOf(" county"));
if (containsCountyPosition > 0) {
map.centerAndZoom(geometryPt,10);
} else {
map.centerAndZoom(geometryPt,12);
}
executeIdentifyTask(geometryPt);
}