Bing map polygons are not returned properly for ISO country type

Ahamed Shajahan 6 Reputation points
2022-10-04T18:50:30.81+00:00

The Bing map with ISO country code does not fetch a proper polygons. For example, I have used SpatialDataService to get the boundary of IND and FRA, but both the resultant polygons are not related to the IND or FRA.

Please provide a solution/code to get the proper Polygons of the given ISO codes.

var Countries = ["IND","FRA"];
Microsoft.Maps.loadModule(['Microsoft.Maps.SpatialDataService', 'Microsoft.Maps.Search'], () => {
var search = new Microsoft.Maps.Search.SearchManager(map);
search.geocode({
where: Countries[0], count: 10, callback: (geocodeResult) => {
type = geocodeResult.results[0].entityType;
},
});
setTimeout(
() => {
var geoDataRequestOptions = {entityType: type,getAllPolygons: true, getEntityMetadata: true};
Microsoft.Maps.SpatialDataService.GeoDataAPIManager.getBoundary(Countries, geoDataRequestOptions, map,
(data) => {
var value = data.location;
if (data.results.length > 0 && data.results[0].Polygons !== null) {
var dataBounds = Microsoft.Maps.LocationRect.fromShapes(data.results[0].Polygons);
var loc = new Microsoft.Maps.Location(dataBounds.center.latitude, dataBounds.center.longitude);
for (var i = 0; i < data.results[0].Polygons.length; i++) {
data.results[0].Polygons[i].setOptions({
fillColor: new Microsoft.Maps.Color(0.5,255,192,203),
});
data.results[0].Polygons[i].metadata = {
shapeName: value,
};
}
map.entities.push(data.results[0].Polygons);
locs.push(loc);
map.setView({ bounds: Microsoft.Maps.LocationRect.fromLocations(locs), padding: 80 });
}
});
}, 100);
});

Windows Maps
Windows Maps
A Microsoft app that provides voice navigation and turn-by-turn driving, transit, and walking directions.
245 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. IoTGirl 2,976 Reputation points Microsoft Employee
    2022-10-05T15:30:24.857+00:00

    Hmmm, I am not sure about your code but I can reproduce the issue. If I use the names "India" & "France" SDS does return the polygons. I made a small code change to the iSDK sample at https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/sdsloadmultipleboundaries lines 6->11 to test

    //Create an array of locations to get the boundaries of  
    var zipCodes = ['India', 'France'];  
    var geoDataRequestOptions = {  
        entityType: 'CountryRegion',  
        getAllPolygons: true  
    };  
    

    The Entity type does need to be CountryRegion and the French ISO code seems to work but not India so I suspect that our Spatial Data Service does not support the ISO code for polygons but I will ask. Is it possible for you to use country names in place of the ISO code in your solution?

    Sincerely,
    IoTGirl


  2. IoTGirl 2,976 Reputation points Microsoft Employee
    2023-01-23T07:41:42.7433333+00:00

    Hi Ahamed,

    I now have some clarity. The ISO statement is for "Output" not "Input". THe input is standard string recognition and does not offer an ISO interpretation so the behaviour we are seeing is as designed and will not be changed as that would impact the intended use case. The best answer is the one I gave previously as the table will be small. Have a translate from ISO to Name before your call to the API and then you will have an ISO input for your use case.

    Sincerely,

    IoTGirl

    0 comments No comments