If you are following this sample: https://samples.bingmapsportal.com/?sample=geodata-search-boundary it does the following:
- Geocodes the input query.
- Takes the first result and uses it's coordinates to find the intersecting boundary using the Geodata API.
Doing a quick test, geocoding "Clark, NV" returns two results. The first has an entityType
of PopulatedPlace
(the city), and the second is AdminDivision2
(the county).
If you are only using the GeoData API and passing in "Clark, NV" as the "address query", it will do the same thing as above and use the coordinate of the first result as the center point of the search. If you specify that you want an AdminDivision2
, it will match with the county that intersects the first result of the geocode (the county the city of Clark, NV is in), in this case Storey County, NV. Not that in the documentation for this API, when using this API with a string input, that input is expected to be an address. If you pass in a higher-level entity such as city or county, you are likely to get a mismatch. The idea here is you pass in an address and can get all the boundaries within the hierarchy of that address (city, zip code, county, state, country).
There are two ways to resolve this issue:
- Geocode the query first and pick the most suitable result. In this case the
AdminDivision2
is the second geocode result when "Clark, NV" is passed in. So, you can check the entity type and choose the one that you prefer. You can then use the coordinates from the preferred result with the GeoData API. - Alternatively, as IoTGirl mentioned, when it comes to US countries, adding the word "county" to the query causes the geocoder to exclude the city result. For example: "Clark county, NV".
I also tested "Clark, NV" in Azure Maps here: https://samples.azuremaps.com/?search=boundary&sample=search-for-boundaries and the county result was found as the first result (city boundary wasn't returned. Not sure if that's a gap, might be due to such low population in that city/town).