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");
<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" />
Angemeldete Mitglieder können Beiträge verfassen, Updates folgen und mehr. Neu hier? Registriere ein kostenloses Konto.
Find useful guides, FAQs, and documents to help you navigate and make the most of Esri Community.