Get the boundary for town.

Balasaheb Molawade 136 Reputation points

Hi Team,

We used the “Spatial Data service module” present on Bing map SDK in the following link to get the boundary of a region. We are facing one issue while getting the boundary of “Moravia NY”. We used entitytype as PopulatedPlace. We want boundary shown in screenshot1 but we are getting boundary shows in screenshot2. Is there any way to get the boundary shows in screenshot1.





Used below code:

var map = new Microsoft.Maps.Map(document.getElementById('myMap'), {
/* No need to set credentials if already passed in URL */
center: new Microsoft.Maps.Location(42.7126, -76.4216),
zoom: 11
//Create an array of locations to get the boundaries of
var regions = ['Moravia NY'];
var geoDataRequestOptions = {
entityType: 'PopulatedPlace',
getAllPolygons: true
Microsoft.Maps.loadModule('Microsoft.Maps.SpatialDataService', function () {
//Use the GeoData API manager to get the boundary
Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(regions, geoDataRequestOptions, map, function (data) {
if (data.results && data.results.length > 0) {
}, null, function errCallback(callbackState, networkStatus, statusMessage) {

Waiting for your reply.



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

1 answer

Sort by: Most helpful
  1. rbrundritt 16,066 Reputation points Microsoft Employee

    It looks like their are two boundaries with the same name (A larger city with a smaller municipality/village within it with the same name:,_New_York). Screenshots 1 and 2 represent these two accordingly. I went through the Bing Maps GeoData API and didn't find any setting that returns the boundary you are looking for. I tried working around this by using a coordinate that is inside of the boundary in the first screenshot, but outside the boundary of the second one, however I still wasn't able to retrieve the boundary you are looking for.

    I've tried the same location in Azure Maps and did however find the boundary you were looking for. In this sample: Enter your query and press search button. Click on the second result (CountryTertiarySubdivision) and you will see the boundary you are looking for. Azure Maps retrieves boundaries a bit differently than Bing Maps. Bing Maps geocodes the query you pass in, then takes the coordinate and finds intersecting boundaries for the specified entity type. Azure Maps geocodes a query and each result has a unique boundary id (if there is a known boundary) which can be used to retrieve that specific boundary. In your scenario this makes it easier to retrieve the specific boundary you are looking for. Here are some additional resources:

    1 person found this answer helpful.
    0 comments No comments