void locator_FindCompleted(object sender, LocatorFindEventArgs e) { GraphicsLayer graphicsLayer = (MyMap.Layers["MyRouteGraphicsLayer"] as GraphicsLayer); if (e.Result != null) { LocatorFindResult findResult = e.Result; Graphic graphicLocation = findResult.Locations[0].Graphic; graphicLocation.Geometry.SpatialReference = MyMap.SpatialReference; graphicLocation.Attributes.Add("name", findResult.Locations[0].Name); _stops.Add(graphicLocation); if ((string)e.UserState == "from") { graphicLocation.Symbol = LayoutRoot.Resources["FromSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; //Geocode to address _locator.FindAsync(ParseSearchText(ToTextBox.Text), "to"); } else { graphicLocation.Symbol = LayoutRoot.Resources["ToSymbol"] as ESRI.ArcGIS.Client.Symbols.Symbol; //Get route between from and to _routeParams.OutSpatialReference = MyMap.SpatialReference; _routeTask.SolveAsync(_routeParams); } graphicsLayer.Graphics.Add(graphicLocation); } }
private async void geocoording_Click(object sender, RoutedEventArgs e) { //マップが準備できていなければ処理を行わない if (!isMapReady) { return; } //住所検索用のパラメータを作成 OnlineLocatorFindParameters parameters = new OnlineLocatorFindParameters(addressTextBox.Text) { MaxLocations = 5, OutSpatialReference = SpatialReferences.WebMercator, OutFields = OutFields.All }; try { //住所の検索 IList <LocatorFindResult> resultCandidates = await onlineLocatorTask.FindAsync(parameters, CancellationToken.None); //住所検索結果に対する処理(1つ以上候補が返されていれば処理を実行) if (resultCandidates != null && resultCandidates.Count > 0) { //現在の結果を消去 geocodeResultGraphicsOverlay.Graphics.Clear(); //常に最初の候補を採用 LocatorFindResult candidate = resultCandidates.FirstOrDefault(); //最初の候補からグラフィックを作成 Graphic locatedPoint = new Graphic() { Geometry = candidate.Feature.Geometry, }; //住所検索結果表示用のグラフィックスオーバーレイにグラフィックを追加 geocodeResultGraphicsOverlay.Graphics.Add(locatedPoint); //追加したグラフィックの周辺に地図を拡大 await MyMapView.SetViewAsync((MapPoint)locatedPoint.Geometry, 36112); } //候補が一つも見つからない場合の処理 else { MessageBox.Show("住所検索:該当する場所がみつかりません。"); } } //エラーが発生した場合の処理 catch (Exception ex) { MessageBox.Show(string.Format("住所検索:{0}", ex.Message)); } }
private void AddGraphicFromLocatorCandidate(LocatorFindResult candidate) { var location = GeometryEngine.Project(candidate.Feature.Geometry, SpatialReferences.Wgs84) as MapPoint; var graphic = new Graphic(location); graphic.Attributes["Name"] = candidate.Name; graphic.Attributes["Address"] = candidate.Feature.Attributes["Place_addr"]; graphic.Attributes["LocationDisplay"] = string.Format("{0:0.000}, {1:0.000}", location.X, location.Y); _addressOverlay.Graphics.Add(graphic); }
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); }
private string GetAttributes(LocatorFindResult result) { if (result == null || !result.Feature.Attributes.Any()) return ""; var v = result.Feature.Attributes; // use the result "name" if the PlaceName attribute is empty. // Reason: when searching for exact addresses and street intersections the attribute fields might // be empty; in particular we don't want to show an empty PlaceName. var placeName = (string)v["PlaceName"]; if (string.IsNullOrEmpty(placeName)) return Result.Name; // use the Placename, Type, City, and Country var s = string.Format("{0}{1}{2}{3}", placeName, string.IsNullOrEmpty((string)v["Type"]) ? "" : ", " + ((string)v["Type"]), string.IsNullOrEmpty((string)v["City"]) ? "" : ", " + ((string)v["City"]), string.IsNullOrEmpty((string)v["Country"]) ? "" : ", " + ((string)v["Country"])); return s; }
public WorldGeocoding() { InitializeComponent(); // Initialize Locator with ArcGIS Online World Geocoding Service. See http://geocode.arcgis.com for details and doc. _locatorTask = new Locator("http://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer"); _locatorTask.FindCompleted += (s, a) => { // When a Find operation is initiated, get the find results and add to a graphics layer for display in the map LocatorFindResult locatorFindResult = a.Result; foreach (Location location in locatorFindResult.Locations) { FindResultLocationsGraphicsLayer.Graphics.Add(location.Graphic); } }; _locatorTask.Failed += (s, e) => { MessageBox.Show("Locator service failed: " + e.Error); }; FindResultLocationsGraphicsLayer = MyMap.Layers["FindResultLocationsGraphicsLayer"] as GraphicsLayer; }
internal Location(int index, LocatorFindResult result) { Index = index; Result = result; }