Hi,My application has a Map and a Box to locate Adresses.My locator is based on the example at http://resources.esri.com/help/9.3/arcgisserver/apis/silverlight/samples/start.htm#AddressToLocation, but the MSVisual Studio says that there's this error on my code.
MainPage.Localizador_LocationToAddressCompleted(object sender, AddressToLocationsEventArgs e)
Error:
No overload for 'Localizador_LocationToAddressCompleted' matches deleagate 'System.EventHandler<ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs>'
the problem is that the code on the link says to do so, and i have no idea how to make this work...here's what i've done so far:CS
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using ESRI.ArcGIS.Client;
using ESRI.ArcGIS.Client.Tasks;
using ESRI.ArcGIS.Client.Geometry;
namespace AdressLocator
{
public partial class MainPage : UserControl
{
List<AddressCandidate> _candidateList;
private bool _firstZoom = true;
private int _lastIndex = 0;
Locator localizador = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/Locators/" +
"ESRI_Geocode_USA/GeocodeServer");
public MainPage()
{
InitializeComponent();
btnAcheEncereço.Click += BtnAcheEncereço_click;
//Here's where the Visual Studio point's the error:
localizador.LocationToAddressCompleted += Localizador_LocationToAddressCompleted;
localizador.Failed += new EventHandler<TaskFailedEventArgs>(Localizador_Failed);
}
private void BtnAcheEncereço_click(object sender, RoutedEventArgs e)
{
AddressToLocationsParameters addressParams = new AddressToLocationsParameters();
Dictionary<string, string> address = addressParams.Address;
if (!string.IsNullOrEmpty(State.Text))
address.Add("Address", Address.Text);
if (!string.IsNullOrEmpty(City.Text))
address.Add("City", City.Text);
if (!string.IsNullOrEmpty(State.Text))
address.Add("State", State.Text);
if (!string.IsNullOrEmpty(Zip.Text))
address.Add("Zip", Zip.Text);
if (addressParams.Address.Count == 0)
{
GraphicsLayer graphicsLayer = mapa.Layers["MyGraphicsLayer"] as GraphicsLayer;
if (graphicsLayer != null)
graphicsLayer.ClearGraphics();
candidateScrollViewer.Content = null;
candidatePanelGrid.Visibility = Visibility.Collapsed;
MessageBox.Show("No address field entered.");
return;
}
localizador.AddressToLocationsAsync(addressParams);
}
private void Localizador_LocationToAddressCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs e)
{
List<AddressCandidate> returnedCandidates = e.Results;
if (returnedCandidates.Count == 0)
{
MessageBox.Show("No address match found.");
return;
}
GraphicsLayer graphicsLayer = mapa.Layers["MyGraphicsLayer"] as GraphicsLayer;
graphicsLayer.ClearGraphics();
_candidateList = new List<AddressCandidate>();
ListBox candidateListBox = new ListBox()
{
BorderThickness = new Thickness(0),
VerticalAlignment = VerticalAlignment.Center
};
foreach (AddressCandidate candidate in returnedCandidates)
{
if (candidate.Score >= 65)
{
_candidateList.Add(candidate);
candidateListBox.Items.Add(candidate.Address);
Graphic graphic = new Graphic()
{
Symbol = DefaultMarkerSymbol,
Geometry = candidate.Location
};
graphic.Attributes.Add("Address", candidate.Address);
string latlon = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y);
graphic.Attributes.Add("LatLon", latlon);
graphicsLayer.Graphics.Add(graphic);
}
}
candidateListBox.SelectionChanged += _candidateListBox_SelectionChanged;
candidateScrollViewer.Content = candidateListBox;
candidatePanelGrid.Visibility = Visibility.Visible;
MapPoint pt = _candidateList[0].Location;
if (_firstZoom)
{
mapa.ZoomToResolution(mapa.Resolution / 4, pt);
_firstZoom = false;
}
else
mapa.PanTo(pt);
_lastIndex = 0;
candidateListBox.SelectedIndex = 0;
}
void _candidateListBox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ListBox listBox = sender as ListBox;
int index = listBox.SelectedIndex;
if (index >= 0 && _lastIndex != index)
{
_lastIndex = index;
AddressCandidate candidate = _candidateList[index];
mapa.PanTo(candidate.Location);
}
}
private void Localizador_Failed(object sender, TaskFailedEventArgs e)
{
MessageBox.Show(e.Error.ToString());
}
}
}
Does Anyone knows how to fix it??