private GeocodeParameters CreateTestGeocodeParamsMultiFieldFull()
        {
            GeocodeParameters gcParams = CreateTestGeocodeParamsMultiFieldBasic();

            gcParams.searchExtent = new double[] { -90, 43.2, -89, 43.0 };
            List <string> categories = new List <string>();

            categories.Add("Address");
            categories.Add("Residence");
            categories.Add("Park");
            gcParams.category = categories;
            SpatialReference outSR = new SpatialReference();

            outSR.wkid             = 102100;
            gcParams.outSRAsObject = outSR;
            List <string> fields = new List <string>();

            fields.Add("*");
            gcParams.outFields       = fields;
            gcParams.maxLocations    = 2;
            gcParams.forStorage      = true;
            gcParams.matchOutOfRange = false;
            gcParams.langCode        = "ES";
            List <string> sourceCountries = new List <string>();

            sourceCountries.Add("USA");
            sourceCountries.Add("CAN");
            gcParams.sourceCountry = sourceCountries;

            return(gcParams);
        }
        /// <summary>
        /// Get location searched by user from the locator
        /// </summary>
        /// <param name="_searchString">User input</param>
        /// <returns>Location that best matches the search string</returns>
        private async Task <GeocodeResult> GetSearchedLocationAsync(string geocodeAddress)
        {
            try
            {
                // Locate the searched feature
                if (Locator != null)
                {
                    var geocodeParameters = new GeocodeParameters
                    {
                        MaxResults = 1,
                        PreferredSearchLocation = AreaOfInterest?.TargetGeometry as MapPoint,
                    };

                    // return the first match
                    var matches = await Locator.GeocodeAsync(geocodeAddress, geocodeParameters);

                    return(matches.FirstOrDefault());
                }
                else
                {
                    ErrorMessage = "Geocoder is not available. Please reload the app. If you continue to receive this message, contact your GIS administrator.";
                    return(null);
                }
            }
            catch (Exception ex)
            {
                ErrorMessage = "Your search request could not be completed";
                StackTrace   = ex.ToString();
                return(null);
            }
        }
        public void GeocodeParametersToQueryStringMultiLineFull()
        {
            GeocodeParameters           gcParams   = CreateTestGeocodeParamsMultiFieldFull();
            Dictionary <string, object> dictOutput = gcParams.ToDictionary();
            var test = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(test, typeof(string), test);
        }
Beispiel #4
0
        private async void Geocoording_Click(object sender, RoutedEventArgs e)
        {
            //マップが準備できていなければ処理を行わない
            if (!isMapReady)
            {
                return;
            }

            //住所検索用のパラメータを作成
            var geocodeParams = new GeocodeParameters
            {
                MaxResults             = 5,
                OutputSpatialReference = SpatialReferences.WebMercator,
                CountryCode            = "Japan",
                OutputLanguage         = new System.Globalization.CultureInfo("ja-JP"),
            };

            try
            {
                //住所の検索
                var resultCandidates = await onlineLocatorTask.GeocodeAsync(addressTextBox.Text, geocodeParams);

                //住所検索結果に対する処理(1つ以上候補が返されていれば処理を実行)
                if (resultCandidates != null && resultCandidates.Count > 0)
                {
                    //現在の結果を消去
                    geocodeResultGraphicsOverlay.Graphics.Clear();

                    //常に最初の候補を採用
                    var candidate = resultCandidates.FirstOrDefault();

                    //最初の候補からグラフィックを作成
                    Graphic locatedPoint = new Graphic()
                    {
                        Geometry = candidate.DisplayLocation,
                    };

                    //住所検索結果表示用のグラフィックスオーバーレイにグラフィックを追加
                    geocodeResultGraphicsOverlay.Graphics.Add(locatedPoint);

                    //追加したグラフィックの周辺に地図を拡大
                    await MyMapView.SetViewpointCenterAsync((MapPoint)locatedPoint.Geometry, 36112);
                }
                //候補が一つも見つからない場合の処理
                else
                {
                    var message = new MessageDialog("住所検索:該当する場所がみつかりません。");
                    await message.ShowAsync();
                }
            }
            //エラーが発生した場合の処理
            catch (Exception ex)
            {
                var message = new MessageDialog(string.Format("住所検索:{0}", ex.Message));
                await message.ShowAsync();
            }
        }
        public void FindAddressCandidatesWithoutTokenReturnsSuccess()
        {
            GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic();
            GeocodeService    service  = new GeocodeService();
            GeocodeResult     result   = service.FindAddressCandidates(gcParams);

            Assert.IsInstanceOfType(result, typeof(GeocodeResult));
            Assert.IsNotNull(result.candidates, "Candidates should not be null.");
            Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null.");
        }
        public void GeocodeParametersToQueryStringMultiLineBasic()
        {
            string                      multiLineBasicJson = "address=James+Madison+Park&address2=614+E+Gorham+St&address3=Basketball+courts&neighborhood=Downtown&city=Madison&subregion=Dane+County&region=WI&postal=53703&countryCode=USA&location=%5b-89.383%2c43.081%5d&forStorage=False&locationType=rooftop&f=json";
            GeocodeParameters           gcParams           = CreateTestGeocodeParamsMultiFieldBasic();
            Dictionary <string, object> dictOutput         = gcParams.ToDictionary();
            var test = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(test, typeof(string), test);
            Assert.AreEqual(test, multiLineBasicJson);
        }
        public void GeocodeParametersToQueryStringSingleLineBasic()
        {
            string                      singleLineBasicJson = "singleLine=614+E+Gorham+St&location=%5b-89.383%2c43.081%5d&outFields=NAME&forStorage=False&locationType=rooftop&f=json";
            GeocodeParameters           gcParams            = CreateTestGeocodeParamsSingleLineBasic();
            Dictionary <string, object> dictOutput          = gcParams.ToDictionary();
            var test = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(test, typeof(string), test);
            Assert.AreEqual(test, singleLineBasicJson);
        }
Beispiel #8
0
        public static async Task <IReadOnlyList <GeocodeResult> > GeocodeAsync(string searchText, Geometry.Geometry?searchArea = null, int maxResults = 10)
        {
            await _geocoder.LoadAsync().ConfigureAwait(false);

            var parameters = new GeocodeParameters()
            {
                MaxResults = maxResults, SearchArea = searchArea
            };

            return(await _geocoder.GeocodeAsync(searchText, parameters).ConfigureAwait(false));
        }
        public void GeocodeParametersToDictionary1()
        {
            GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic();

            Dictionary <string, object> dictOutput = gcParams.ToDictionary();

            foreach (var entry in dictOutput)
            {
                string kvp = entry.Key + ": " + entry.Value;
                Console.WriteLine(kvp);
            }
            Assert.IsNotNull(dictOutput);
            Assert.IsInstanceOfType(dictOutput, typeof(Dictionary <string, object>));
        }
        private GeocodeParameters CreateTestGeocodeParamsSingleLineBasic()
        {
            GeocodeParameters gcParams = new GeocodeParameters();

            gcParams.singleLine = "614 E Gorham St";
            List <string> fields = new List <string>();

            fields.Add("NAME");
            gcParams.outFields    = fields;
            gcParams.location     = new double[] { -89.383, 43.081 };
            gcParams.forStorage   = false;
            gcParams.locationType = LocationType.rooftop;

            return(gcParams);
        }
        public void FindAddressCandidatesMultiLineFull()
        {
            GeocodeParameters           gcParams   = CreateTestGeocodeParamsMultiFieldFull();
            Dictionary <string, object> dictOutput = gcParams.ToDictionary();
            var test = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(test, typeof(string), test);

            GeocodeService service = new GeocodeService();
            GeocodeResult  result  = service.FindAddressCandidates(gcParams, this.Token);

            Assert.IsInstanceOfType(result, typeof(GeocodeResult));
            Assert.IsNotNull(result.candidates, "Candidates should not be null.");
            Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null.");
        }
        public void FindAddressCandidatesWithoutTokenForStorageThrowsException()
        {
            GeocodeParameters gcParams = CreateTestGeocodeParamsSingleLineBasic();

            gcParams.forStorage = true;
            GeocodeService service = new GeocodeService();

            try
            {
                GeocodeResult result = service.FindAddressCandidates(gcParams);
            }
            catch (Exception ex)
            {
                Assert.IsInstanceOfType(ex, typeof(GeocodeException));
            }
        }
        public void FindAddressCandidatesMultiLineBasic()
        {
            string                      multiLineBasicJson = "address=James+Madison+Park&address2=614+E+Gorham+St&address3=Basketball+courts&neighborhood=Downtown&city=Madison&subregion=Dane+County&region=WI&postal=53703&countryCode=USA&location=%5b-89.383%2c43.081%5d&forStorage=False&locationType=rooftop&f=json";
            GeocodeParameters           gcParams           = CreateTestGeocodeParamsMultiFieldBasic();
            Dictionary <string, object> dictOutput         = gcParams.ToDictionary();
            var test = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(test, typeof(string), test);
            Assert.AreEqual(test, multiLineBasicJson);

            GeocodeService service = new GeocodeService();
            GeocodeResult  result  = service.FindAddressCandidates(gcParams, this.Token);

            Assert.IsInstanceOfType(result, typeof(GeocodeResult));
            Assert.IsNotNull(result.candidates, "Candidates should not be null.");
            Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null.");
        }
        public void FindAddressCandidatesSingleLineBasic()
        {
            string                      singleLineBasicJson = "singleLine=614+E+Gorham+St&location=%5b-89.383%2c43.081%5d&outFields=NAME&forStorage=False&locationType=rooftop&f=json";
            GeocodeParameters           gcParams            = CreateTestGeocodeParamsSingleLineBasic();
            Dictionary <string, object> dictOutput          = gcParams.ToDictionary();
            string                      queryString         = dictOutput.ToQueryString();

            Assert.IsInstanceOfType(queryString, typeof(string), queryString);
            Assert.AreEqual(queryString, singleLineBasicJson);

            GeocodeService service = new GeocodeService();
            GeocodeResult  result  = service.FindAddressCandidates(gcParams, this.Token);

            Assert.IsInstanceOfType(result, typeof(GeocodeResult));
            Assert.IsNotNull(result.candidates, "Candidates should not be null.");
            Assert.IsNotNull(result.spatialReference, "Spatial Reference should not be null.");
        }
Beispiel #15
0
        private async Task <MapPoint> GeocodeArtistPlacename(string placeName)
        {
            MapPoint          matchedPoint = null;
            LocatorTask       locatorTask  = new LocatorTask(new System.Uri(_locatorUrl));
            GeocodeParameters p            = new GeocodeParameters
            {
                MaxResults = 1,
                MinScore   = 85
            };
            IReadOnlyList <GeocodeResult> placeMatches = await locatorTask.GeocodeAsync(placeName, p);

            if (placeMatches.Count > 0)
            {
                GeocodeResult place = placeMatches.FirstOrDefault();
                matchedPoint = place.DisplayLocation;
            }

            return(matchedPoint);
        }
Beispiel #16
0
        /// <inheritdoc />
        public override async Task <IList <SearchResult> > SearchAsync(SearchSuggestion suggestion, CancellationToken cancellationToken = default)
        {
            await _additionalLoadTask;

            cancellationToken.ThrowIfCancellationRequested();

            var tempParams = new GeocodeParameters();

            foreach (var attribute in GeocodeParameters.ResultAttributeNames)
            {
                tempParams.ResultAttributeNames.Add(attribute);
            }

            var results = await Locator.GeocodeAsync(suggestion.UnderlyingObject as SuggestResult, tempParams, cancellationToken);

            cancellationToken.ThrowIfCancellationRequested();

            return(await ResultToSearchResult(results));
        }
        private GeocodeParameters CreateTestGeocodeParamsMultiFieldBasic()
        {
            GeocodeParameters gcParams = new GeocodeParameters();

            gcParams.address      = "James Madison Park";
            gcParams.address2     = "614 E Gorham St";
            gcParams.address3     = "Basketball courts";
            gcParams.neighborhood = "Downtown";
            gcParams.city         = "Madison";
            gcParams.subregion    = "Dane County";
            gcParams.region       = "WI";
            gcParams.postal       = "53703";
            gcParams.postalExt    = null;
            gcParams.countryCode  = "USA";
            gcParams.location     = new double[] { -89.383, 43.081 };
            gcParams.forStorage   = false;
            gcParams.locationType = LocationType.rooftop;

            return(gcParams);
        }
        /// <summary>
        /// Runs a search and populates the map with results based on the provided information
        /// </summary>
        /// <param name="enteredText">Results to search for</param>
        /// <param name="locationText">Location around which to find results</param>
        /// <param name="restrictToExtent">If true, limits results to only those that are within the current extent</param>
        private async void UpdateSearch(string enteredText, string locationText, bool restrictToExtent = false)
        {
            // Clear any existing markers
            MyMapView.GraphicsOverlays.Clear();

            // Return gracefully if the textbox is empty or the geocoder isn't ready
            if (string.IsNullOrWhiteSpace(enteredText) || _geocoder == null) { return; }

            // Create the geocode parameters
            GeocodeParameters parameters = new GeocodeParameters();

            // Get the MapPoint for the current search location
            MapPoint searchLocation = await GetSearchMapPoint(locationText);

            // Update the geocode parameters if the map point is not null
            if (searchLocation != null)
            {
                parameters.PreferredSearchLocation = searchLocation;
            }

            // Update the search area if desired
            if (restrictToExtent)
            {
                // Get the current map extent
                Geometry extent = MyMapView.VisibleArea;

                // Update the search parameters
                parameters.SearchArea = extent;
            }

            // Show the progress bar
            MyProgressBar.Visibility = Visibility.Visible;

            // Get the location information
            IReadOnlyList<GeocodeResult> locations = await _geocoder.GeocodeAsync(enteredText, parameters);

            // Stop gracefully and show a message if the geocoder does not return a result
            if (locations.Count < 1)
            {
                MyProgressBar.Visibility = Visibility.Collapsed; // 1. Hide the progress bar
                ShowStatusMessage("No results found"); // 2. Show a message
                return; // 3. Stop
            }

            // Create the GraphicsOverlay so that results can be drawn on the map
            GraphicsOverlay resultOverlay = new GraphicsOverlay();

            // Add each address to the map
            foreach (GeocodeResult location in locations)
            {
                // Get the Graphic to display
                Graphic point = await GraphicForPoint(location.DisplayLocation);

                // Add the specific result data to the point
                point.Attributes["Match_Title"] = location.Label;

                // Get the address for the point
                IReadOnlyList<GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(location.DisplayLocation);

                // Add the first suitable address if possible
                if (addresses.Count() > 0)
                {
                    point.Attributes["Match_Address"] = addresses.First().Label;
                }

                // Add the Graphic to the GraphicsOverlay
                resultOverlay.Graphics.Add(point);
            }

            // Hide the progress bar
            MyProgressBar.Visibility = Visibility.Collapsed;

            // Add the GraphicsOverlay to the MapView
            MyMapView.GraphicsOverlays.Add(resultOverlay);

            // Create a viewpoint for the extent containing all graphics
            Viewpoint viewExtent = new Viewpoint(resultOverlay.Extent);

            // Update the map viewpoint
            MyMapView.SetViewpoint(viewExtent);
        }
Beispiel #19
0
        private async Task UpdateSearch(string enteredText, string locationText, bool restrictToExtent = false)
        {
            // Clear any existing markers.
            _myMapView.GraphicsOverlays.Clear();

            // Return gracefully if the textbox is empty or the geocoder isn't ready.
            if (String.IsNullOrWhiteSpace(enteredText) || _geocoder == null)
            {
                return;
            }

            // Create the geocode parameters.
            GeocodeParameters parameters = new GeocodeParameters();

            // Get the MapPoint for the current search location.
            MapPoint searchLocation = await GetSearchMapPoint(locationText);

            // Update the geocode parameters if the map point is not null.
            if (searchLocation != null)
            {
                parameters.PreferredSearchLocation = searchLocation;
            }

            // Update the search area if desired.
            if (restrictToExtent)
            {
                // Get the current map extent.
                Geometry extent = _myMapView.VisibleArea;

                // Update the search parameters.
                parameters.SearchArea = extent;
            }

            // Show the progress bar.
            _myProgressBar.Visibility = Android.Views.ViewStates.Visible;

            // Get the location information.
            IReadOnlyList <GeocodeResult> locations = await _geocoder.GeocodeAsync(enteredText, parameters);

            // Stop gracefully and show a message if the geocoder does not return a result.
            if (locations.Count < 1)
            {
                _myProgressBar.Visibility = Android.Views.ViewStates.Gone; // 1. Hide the progress bar.
                ShowMessage("No results found", "Alert");                  // 2. Show a message.
                return;                                                    // 3. Stop.
            }

            // Create the GraphicsOverlay so that results can be drawn on the map.
            GraphicsOverlay resultOverlay = new GraphicsOverlay();

            // Add each address to the map.
            foreach (GeocodeResult location in locations)
            {
                // Get the Graphic to display.
                Graphic point = await GraphicForPoint(location.DisplayLocation);

                // Add the specific result data to the point.
                point.Attributes["Match_Title"] = location.Label;

                // Get the address for the point.
                IReadOnlyList <GeocodeResult> addresses = await _geocoder.ReverseGeocodeAsync(location.DisplayLocation);

                // Add the first suitable address if possible.
                if (addresses.Any())
                {
                    point.Attributes["Match_Address"] = addresses.First().Label;
                }

                // Add the Graphic to the GraphicsOverlay.
                resultOverlay.Graphics.Add(point);
            }

            // Hide the progress bar.
            _myProgressBar.Visibility = Android.Views.ViewStates.Gone;

            // Add the GraphicsOverlay to the MapView.
            _myMapView.GraphicsOverlays.Add(resultOverlay);

            // Update the map viewpoint.
            await _myMapView.SetViewpointGeometryAsync(resultOverlay.Extent, 50);
        }