本文整理汇总了C#中Locator.FindAsync方法的典型用法代码示例。如果您正苦于以下问题:C# Locator.FindAsync方法的具体用法?C# Locator.FindAsync怎么用?C# Locator.FindAsync使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Locator
的用法示例。
在下文中一共展示了Locator.FindAsync方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FindButton_Click
private void FindButton_Click(object sender, RoutedEventArgs e)
{
if (string.IsNullOrEmpty(SearchTextBox.Text))
return;
// Clear existing graphics for a new search
FindResultLocationsGraphicsLayer.Graphics.Clear();
MyLocationGraphicsLayer.Graphics.Clear();
MyRoutesGraphicsLayer.Graphics.Clear();
// Initialize the LocatorTask with the Esri World Geocoding Service
var locatorTask = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer");
// In this sample, the center of the map is used as the location from which results will be ranked and distance calculated.
// The distance from the location is optional. Specifies the radius of an area around a point location which is used to boost
// the rank of geocoding candidates so that candidates closest to the location are returned first. The distance value is in meters.
LocatorFindParameters locatorFindParams = new LocatorFindParameters()
{
Text = SearchTextBox.Text,
Location = MyMap.Extent.GetCenter(),
Distance = MyMap.Extent.Width / 2,
MaxLocations = 5,
OutSpatialReference = MyMap.SpatialReference,
SearchExtent = MyMap.Extent
};
locatorFindParams.OutFields.AddRange(new string[] { "PlaceName", "City", "Region", "Country", "Score", "Distance", "Type" });
locatorTask.FindCompleted += (s, ee) =>
{
// When a Find operation is initiated, get the find results and add to a graphics layer for display in the map
LocatorFindResult locatorFindResult = ee.Result;
foreach (Location location in locatorFindResult.Locations)
{
// Make sure results have the right spatial reference
location.Graphic.Geometry.SpatialReference = MyMap.SpatialReference;
FindResultLocationsGraphicsLayer.Graphics.Add(location.Graphic);
}
};
locatorTask.Failed += (s, ee) =>
{
MessageBox.Show("Locator service failed: " + ee.Error);
};
locatorTask.FindAsync(locatorFindParams);
}
示例2: FindLocationsWithSearchText
private void FindLocationsWithSearchText(string searchText)
{
if(MyMap == null) return;
EnableSearchMenuItem(false);
EnableDirectionsButton(false);
UpdateLayer("HighlightLayer", true, false);
UpdateLayer("DestinationLayer", true, false);
var l = UpdateLayer("FindResultsLayer", true, true);
#region Locator - Finds nearest business and triggers reverse geocode to get addresses for locations
var locator = new Locator(GEOCODE_URL);
locator.FindCompleted += (s, e) =>
{
MyProgressBar.IsIndeterminate = false;
var locations = e.Result.Locations;
if (locations.Count > 0)
{
UpdateSearchResultsPanel(locations);
GetAddressesOfLocations(l.Graphics); // Reverse geocode locations
}
else
MessageBox.Show(string.Format("No locations found for '{0}'", searchText));
};
locator.Failed += (s, e) =>
{
MyProgressBar.IsIndeterminate = false;
MessageBox.Show(string.Format("Find '{0}' failed with error '{1}'", SearchFieldTb.Text.Trim(), e.Error.Message));
ShowElement(MyMap);
};
MyProgressBar.IsIndeterminate = true;
locator.FindAsync(new LocatorFindParameters()
{
Text = searchText,
OutSpatialReference = MyMap.SpatialReference,
SearchExtent = MyMap.Extent,
Location = (MyMap.Layers["MyGpsLayer"] as GpsLayer).Position,
Distance = DISTANCE,
MaxLocations = MAX_RESULTS
});
#endregion
}