Get the boundary for town.

Balasaheb Molawade 136 Reputation points
2021-02-22T13:02:12.21+00:00

Hi Team,

We used the “Spatial Data service module” present on Bing map SDK in the following link https://www.bing.com/api/maps/sdk/mapcontrol/isdk/sdsloadmultipleboundaries 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.

Screenshot1:

70627-1.png

Screenshot2:

70628-2.png

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) {
map.entities.push(data.results[0].Polygons);
}
}, null, function errCallback(callbackState, networkStatus, statusMessage) {
console.log(callbackState);
console.log(networkStatus);
console.log(statusMessage);
});
});

Waiting for your reply.

Thanks!

Balasaheb

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
    2021-02-22T17:41:14.66+00:00

    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: https://en.wikipedia.org/wiki/Moravia,_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: https://azuremapscodesamples.azurewebsites.net/?sample=Search%20for%20boundaries 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:

    https://learn.microsoft.com/en-us/rest/api/maps/search/getsearchaddress

    https://learn.microsoft.com/en-us/rest/api/maps/search/getsearchpolygon

    https://learn.microsoft.com/en-us/azure/azure-maps/how-to-use-best-practices-for-search

    https://azure.com/maps

    1 person found this answer helpful.
    0 comments No comments