Select to view content in your preferred language

The problem with LocatorTask is retrieving all objects within a category

146
2
11-23-2024 06:36 AM
Labels (3)
AndreyTsar
New Contributor

Hello! I want to retrieve all objects related to a category, but the search result returns 0 objects.

My code:

var locatorTask = new LocatorTask(new Uri("https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"));
GeocodeParameters param = new GeocodeParameters();
param.MaxResults = 100;
if (map.VisibleArea != null)
param.SearchArea = map.VisibleArea;
else return;
param.MinScore = 1;
param.ResultAttributeNames.Add("*");
param.Categories.Add("POI");
param.Categories.Add("13035");
param.Categories.Add("Coffee");

var res = await locatorTask.GeocodeAsync("", param);
foreach (var item in res)
{
TXTstat.Text = $"{TXTstat.Text}{item.Attributes["PlaceName"]}\n";
}

Tags (3)
0 Kudos
2 Replies
ViktorSafar
Frequent Contributor

Well, the 1st param for GeocodeAsync() is an address and you're not supplying any. https://developers.arcgis.com/rest/services-reference/enterprise/geocode-service/

0 Kudos
GKmieliauskas
Esri Regular Contributor

Hi,

I have edited code from the Find Place sample (MAUI). Code below:

GeocodeParameters parameters = new GeocodeParameters();

// Get the current map extent.
Geometry extent = MyMapView.VisibleArea;

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

var locatorTask = new LocatorTask(new Uri("https://geocode-api.arcgis.com/arcgis/rest/services/World/GeocodeServer"));

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

// Stop gracefully and show a message if the geocoder does not return a result.
if (locations.Count < 1)
{
                    return; // 3. Stop.
}

It works and returns locations. Sample is here:

 

https://github.com/Esri/arcgis-maps-sdk-dotnet-samples/tree/main/src/MAUI/Maui.Samples/Samples/Searc...  

0 Kudos