I have used getBoundary() to get the polygons for my country datasource. For 'BE' I expect the Belgium coordinates, instead am getting the coordinates for Togo. Similarly am getting different results for 'ES', 'SK' and 'IN' as well. Here I have hardcoded the countries datasource. But in real time, the datasource will subject to change dynamically based on user inputs. it can be either a city, state/county or country. so, we set the entity type dynamically using first data. Is there any way to the get the expected results say Belgium for BE, India for IN and Spain for ES.?
function GetMap() {
var map = new Microsoft.Maps.Map('#myMap', {
credentials:"",
});
//Create an array of locations to get the boundaries of.
var Countries = ['AU', 'BE', 'ES', 'SK', 'IN'];
var type = '';
var locs = [];
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; //tslint:disable-line:max-line-length
},
});
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),
strokeColor: '#FFB6C1',
});
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);
});
}
TIA