I am trying to do geocoding using flex api... Here is the issue.
After typing the address, press the find button. What I need: It should show point on the map.. and also use this point, query a layer (say county/tract) to get the results(like county code, tract code) from this layer without any click on the map
I tried to use the identify feature shown in the example, but the results.length becomes zero. and did not show any results.
here is the find address: private function doFind():void { var parameters:AddressToLocationsParameters = new AddressToLocationsParameters(); myGraphicsLayer.clear(); parameters.address = { SingleLine: onelineaddress.text }; // Use outFields to get back extra information // The exact fields available depends on the specific Locator used. parameters.outFields = [ "Loc_name" ]; locator.addressToLocations(parameters, new AsyncResponder(onResult, onFault)); function onResult(candidates:Array, token:Object = null):void { if (candidates.length > 0) { var addressCandidate:AddressCandidate = candidates[0]; var myGraphic:Graphic = new Graphic(); var myGraphicWGS:Graphic = new Graphic(); // for 9.3 servers, or anything else returning latlong: myGraphic.geometry = WebMercatorUtil.geographicToWebMercator(addressCandidate.location); myGraphic.geometry = addressCandidate.location; myGraphic.symbol = mySymbol; myGraphic.toolTip = addressCandidate.address.toString(); myGraphic.id = "graphic"; myGraphicsLayer.add(myGraphic); MainMap.centerAt(myGraphic.geometry as MapPoint); // Zoom to an appropriate level // Note: your attribute and field value might differ depending on which Locator you are using... if (addressCandidate.attributes.Loc_name.search("RoofTop") > 0) // US_RoofTop { MainMap.scale = 10000; } else if (addressCandidate.attributes.Loc_name.search("Address") > 0) { MainMap.scale = 10000; } else if (addressCandidate.attributes.Loc_name.search("Street") > 0) // US_Streets, CAN_Streets, CAN_StreetName, EU_Street_Addr* or EU_Street_Name* { MainMap.scale = 15000; } else if (addressCandidate.attributes.Loc_name.search("ZIP4") > 0 || addressCandidate.attributes.Loc_name.search("Postcode") > 0) // US_ZIP4, CAN_Postcode { MainMap.scale = 20000; } else if (addressCandidate.attributes.Loc_name.search("Zipcode") > 0) // US_Zipcode { MainMap.scale = 40000; } else if (addressCandidate.attributes.Loc_name.search("City") > 0) // US_CityState, CAN_CityProv { MainMap.scale = 150000; } else { MainMap.scale = 500000; } //vboxlatlong.visible=true; var wgsmappoint:MapPoint = WebMercatorUtil.webMercatorToGeographic(addressCandidate.location) as MapPoint; //labellongitude.text = (wgsmappoint.x.toFixed(5)).toString(); //labellatitude.text = (wgsmappoint.y.toFixed(5)).toString(); labeladdressresult.text = "<b>Address Found:</b><br/>" + addressCandidate.address.toString(); // formated address //identify doIdentify(wgsmappoint); } else { //vboxlatlong.visible=false;// //labellongitude.text=""; //labellatitude.text=""; labeladdressresult.text = "<b><font color='#FF0000'>Found nothing !!</b></font>"; Alert.show("Sorry, couldn't find a location for this address" + "\nAddress: " + onelineaddress.text); }; }
here is the doIdentify (without using any mouse click)
private function doIdentify(mpoint:MapPoint):void{ //clickGraphicsLayer.clear(); //Alert.show("Hey" + mpoint.x.toString()); var identifyParams:IdentifyParameters = new IdentifyParameters(); identifyParams.returnGeometry = true; identifyParams.tolerance = 1; identifyParams.width = MainMap.width; identifyParams.height = MainMap.height; identifyParams.geometry = mpoint; identifyParams.mapExtent = MainMap.extent; identifyParams.spatialReference = MainMap.spatialReference; //Alert.show(mpoint.x.toString()); //var mappoint:MapPoint = new MapPoint(); //mappoint = mpoint; var clickGraphic:Graphic = new Graphic(mpoint, clickPtSym); clickGraphicsLayer.add(clickGraphic); identifyTask.execute(identifyParams, new AsyncResponder(myResultFunction, myFaultFunction, clickGraphic)); }
results.length shows zero
private function myResultFunction(results:Array, clickGraphic:Graphic = null):void { // Alert.show(" i m ahere result function "); Alert.show(" i m ahere result function " + results.length.toString()); if (results && results.length > 0) { var result:IdentifyResult = results[0]; var resultGraphic:Graphic = result.feature; //Alert.show(resultGraphic.attributes.toString()); switch (resultGraphic.geometry.type) { case Geometry.MAPPOINT: { resultGraphic.symbol = smsIdentify; break; } } lastIdentifyResultGraphic = resultGraphic; //paneltractresult.visible = true; } }