当前位置: 首页>>代码示例>>C#>>正文


C# Locator.FindAsync方法代码示例

本文整理汇总了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);
        }
开发者ID:GlenDhu,项目名称:tips-and-tricks-wpf,代码行数:47,代码来源:MainWindow.xaml.cs

示例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
 }
开发者ID:jNery,项目名称:geocode_and_routing_wp8,代码行数:40,代码来源:MainPage.xaml.cs


注:本文中的Locator.FindAsync方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。