azure-maps

Is there a way to get the latitude & longitude for a county in the U.S. using Azure Maps?


A fair number of the users of my app do not want to provide their address. But they are ok with providing their county & state (no zip code). I use their location to provide them with events near them. So I need to get the latitude & longitude of the center (or center-ish) point of that county.

I use Azure Maps. Is there a call in Azure Maps to pass in a "county, state" and get back the location?

I use MapsSearchClient.SearchAddress("1 Main St., Anytown, CO, 80000") if I have an address.

I use:

var address = new StructuredAddress()
{
    PostalCode = zipCode,
    CountryCode = "US"
};
var result = await SearchClient.SearchStructuredAddressAsync(address);

If I only have a zip code.

Is there some way to use StructuredAddress if all I have is county, state, and "US"?


Solution

  • Note that the Client libraries for Azure Maps are in "prerelese" state and are regularly being updated. Most notable is that Azure Maps has newer search services for geocoding, reverse geocoding, and boundary retrieval. If you get the latest version of this client library you will find that the SearchStructuredAddressAsync method no longer exists as that is from the old search services, had access to less data, and was generally less accurate than the latest geocoding service. Here is how you would use the latest version of that library to retrieve a county result.

    Response<GeocodingResponse> searchResult = client.GetGeocoding("", new Azure.Maps.Search.Models.Queries.GeocodingQuery()
    {
        AdminDistrict2 = "King", //County
        AdminDistrict = "WA", //State
        CountryRegion = "US"
    });