Select to view content in your preferred language

Setting up a Silverlight Address Locator

710
2
09-03-2010 08:21 AM
ChrisBryce
Deactivated User
Hi all,

I have been trying for several days now to get a functioning address locator into my silverlight web map.

I have followed the ESRI instructions step by step several times using Expression Blend (4), but the instructions don't quite factor in all the linking problems that occur when you are copying code.

A link to that guide here

The only functionality I will need is the address to location function, I won't need the location to address function in my map.

I have my own geocoding services and map services running, and they are functioning just fine in our other hosted maps, I want to eventually redirect these services to silverlight.

However for now I am willing to settle for ANY functioning address finder as long as it builds. That way I can at least retrace the code and tinker around and figure out.

Any help at all would be most appreciated!
0 Kudos
2 Replies
DarinaTchountcheva
Frequent Contributor
Hi Chris,

Have you tried the AddressToLocation sample in the Interactive Samples library?

http://help.arcgis.com/en/webapi/silverlight/samples/start.htm#AddressToLocation

Depending on your Locator, you might have to remove some lines of code in XAML and code behind(for City, Zip, State, LatLon, ...), and you have to replace the geocoding service's url with your url.

If you are still having troubles, you will have to give us more info about your geocoding service.

Good Luck!
0 Kudos
ChrisBryce
Deactivated User
Thanks for the response!

I have gotten the map now to draw the icon correctly, however it will not calcuate the proper address down to a high resolution than the City/State/ZIP.  The address field entries seems to make no difference.

Here is the code.
private void FindAddressButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
         
   Locator locatorTask = new Locator("http://sampleserver1.arcgisonline.com/ArcGIS/rest/services/" +
    "Locators/ESRI_Geocode_USA/GeocodeServer");

   locatorTask.AddressToLocationsCompleted += LocatorTask_AddressToLocationsCompleted;
     

   
   AddressToLocationsParameters addressParameters = new AddressToLocationsParameters();
   Dictionary<string, string> address = addressParameters.Address;

   address.Add("Address", Address.Text);
   address.Add("City", City.Text);
   address.Add("State", State.Text);
   address.Add("Zip", Zip.Text);

   
   
   locatorTask.AddressToLocationsAsync(addressParameters);
  }

  
  private void LocatorTask_AddressToLocationsCompleted(object sender, ESRI.ArcGIS.Client.Tasks.AddressToLocationsEventArgs args)
  {
   
   if (args.Results.Count > 0)
   {
    // Get the best match
    AddressCandidate bestCandidate = args.Results[0];
    foreach (AddressCandidate candidate in args.Results)
     bestCandidate = (candidate.Score > bestCandidate.Score) ? candidate : bestCandidate;

    
    Graphic graphic = new Graphic()
    {
     Symbol = AddressToLocationSymbol,
     Geometry = bestCandidate.Location
    };

    
    graphic.Attributes.Add("Address", bestCandidate.Address);
    graphic.Attributes.Add("City", bestCandidate.Address);
    string latLon = String.Format("{0}, {1}", bestCandidate.Location.X, bestCandidate.Location.Y);
    graphic.Attributes.Add("LatLon", latLon);

    
    GraphicsLayer graphicsLayer = Map.Layers["AddressToLocationGraphicsLayer"] as GraphicsLayer;
    graphicsLayer.ClearGraphics();
    graphicsLayer.Graphics.Add(graphic);
   }
   else
   {
    
    MessageBox.Show("No results found");


As you can see, it is pretty much the exact code found in the guide above, and it also uses the ESRI geocoder. So i thought maybe the error is in the xaml code.  However I cant seem to find anything in there either that looks awry.

<StackPanel Margin="27,18,0,8" HorizontalAlignment="Left" >
          <TextBlock Text="Click Find to locate an address" HorizontalAlignment="Center" 
           Margin="0,0,0,5" Foreground="Black" FontStyle="Italic" />
          <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
     <TextBlock Text="Address: " Foreground="Black" />
     <TextBox x:Name="Address" Text="510 W 9th" Width="125" />
    </StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
     <TextBlock Text="City: " Foreground="Black" />
     <TextBox x:Name="City" Text="Georgetown" Width="125" />
    </StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
     <TextBlock Text="State: " Foreground="Black" />
     <TextBox x:Name="State" Text="TX" Width="125"/>
    </StackPanel>
    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" >
     <TextBlock Text="Zip: " Foreground="Black" />
     <TextBox x:Name="Zip" Text="" Width="125" />
    </StackPanel>

          <Button x:Name="FindAddressButton" Content="Find" Width="176" HorizontalAlignment="Center" Margin="0,5,0,0" Click="FindAddressButton_Click" />
     <Line HorizontalAlignment="Center" X1="0" Y1="10" X2="180" Y2="10" StrokeThickness="1" Stroke="White" />


I am thinking that perhaps it has something to do with which results to draw, and as a result it is not drawing the correct number of points.  OR the address field is messed up some how and is not putting in correct results.

However, when I enter the exact same address here , it pulls up the correct results.


Do you know what could be making this happen?

Thanks again!
0 Kudos