Hi there, I could use some help getting my address locator to work with my silverlight page. It seems to work OK with a straight /NET page but I'm missing something in the transfer to silverlight. Here's my code. You can tell by the comments some of the things I have tried. (Morton - The REST endpoint is now working.) Private Sub FindAddressButton_Click(ByVal sender As Object, ByVal e As RoutedEventArgs)
Dim locatorTask As New Locator("http://maps.pagnet.org/arcgis/rest/services/PAGAddressLocator/GeocodeServer")
AddHandler locatorTask.AddressToLocationsCompleted, AddressOf LocatorTask_AddressToLocationsCompleted
AddHandler locatorTask.Failed, AddressOf LocatorTask_Failed
Dim addressParams As New AddressToLocationsParameters()
Dim addressDictionary As Dictionary(Of String, String) = addressParams.Address
If (Not String.IsNullOrEmpty(Address.Text)) Then
addressDictionary.Add("Street", Address.Text)
End If
'If (Not String.IsNullOrEmpty(City.Text)) Then
' addressDictionary.Add("City", City.Text)
'End If
'If (Not String.IsNullOrEmpty(State.Text)) Then
' addressDictionary.Add("State", State.Text)
'End If
'If (Not String.IsNullOrEmpty(Zip.Text)) Then
' addressDictionary.Add("Zip", Zip.Text)
'End If
locatorTask.AddressToLocationsAsync(addressParams)
End Sub
Private Sub LocatorTask_AddressToLocationsCompleted(ByVal sender As Object, ByVal args As ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs)
Dim returnedCandidates As List(Of AddressCandidate) = args.Results
Dim graphicsLayer As GraphicsLayer = TryCast(MyMap.Layers("MyGraphicsLayer"), GraphicsLayer)
graphicsLayer.ClearGraphics()
Dim _candidateList = New List(Of AddressCandidate)()
Dim candidateListBox As New ListBox()
For Each candidate As AddressCandidate In returnedCandidates
If candidate.Score >= 95 Then
_candidateList.Add(candidate)
candidateListBox.Items.Add(candidate.Address)
Dim graphic As New Graphic() With {.Symbol = DefaultMarkerSymbol, .Geometry = candidate.Location}
' graphic.Attributes.Add("street", candidate.Address)
graphic.Attributes.Add("Address", candidate.Address)
'Dim latlon As String = String.Format("{0}, {1}", candidate.Location.X, candidate.Location.Y)
'graphic.Attributes.Add("LatLon", latlon)
graphicsLayer.Graphics.Add(graphic)
End If
Next candidate
AddHandler candidateListBox.SelectionChanged, AddressOf _candidateListBox_SelectionChanged
CandidateScrollViewer.Content = candidateListBox
CandidatePanelGrid.Visibility = Visibility.Visible
Dim pt As MapPoint = _candidateList(0).Location
If _firstZoom Then
MyMap.ZoomToResolution(MyMap.Resolution / 4, pt)
_firstZoom = False
Else
MyMap.PanTo(pt)
End If
_lastIndex = 0
candidateListBox.SelectedIndex = 0
End Sub