Limit search by country

Shimmy Weitzhandler 286 Reputation points
2025-03-05T14:47:50.6966667+00:00
var address = "Prospects Place, Fairfax Drive, Westcliff-on-Sea";
var client = new MapsSearchClient(credential);
var response = await client.GetGeocodingAsync(query: address, cancellationToken: cancellationToken);
var isSuccess = response.GetRawResponse().Status == StatusCodes.Status200OK;

if (!isSuccess || response.Value.Features.Count == 0)
{
    logger.LogWarning("Could not parse address {Address}", address);
    throw new InvalidOperationException($"Could not parse address '{address}'.");
}

var feature = response.Value.Features.First();
var result = feature.Properties.Address;

Is there a way to limit the search to be in a specific country only

Azure Maps
Azure Maps
An Azure service that provides geospatial APIs to add maps, spatial analytics, and mobility solutions to apps.
796 questions
0 comments No comments
{count} votes

Accepted answer
  1. rbrundritt 19,831 Reputation points Microsoft Employee
    2025-03-05T17:50:30.7266667+00:00

    The latest version of the geocoding service in Azure Maps does not have an option for limiting the search a single country. A feature request has been made to Azure Maps to bring this option to latest version of the geocoding service.

    One common workaround for this is to append the country code to the query. For example: "your query" + ", GB". You may still end up with results from outside the specified country, but results in the specified country are likely to have more weight and be the top results. That said, for your query this doesn't appear to help, most likely because you are passing in the building name which is a point of interest name and not an address line.

    The V1 Azure Maps Search service does however have an option to limit the query to a specific country called countrySet. As noted on another thread to your question, there is a great open source .NET client library for Azure Maps that wraps the v1 services: https://github.com/perfahlen/AzureMapsRestServices

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.