# Bing Maps V8 LocationRect fromLocations

• ### Question

• Just a suggestion, but it would be nice if LocationRect could have an additional 'fromRings', or 'fromPolygon' function, as passing the locations from a polygon using the following...

`map.setView({bounds: Microsoft.Maps.LocationRect.fromLocations(myPolygon.getLocations()});`

only takes the locations from the first ring of the polygon. I have to write a fair bit of code to get the bounding box of an entire polygon. I appreciate that this is probably a hangover from V7, before complex polygons were supported, but given the improvements I think this has been overlooked.

I've written the following, but if there's a better way of doing it, any advice would be appreciated.

```var rings = myPolygon.getRings()
var n, e, s, w;
for (var i = 0, len = rings.length; i < len; i++) {
var br = Microsoft.Maps.LocationRect.fromLocations(rings[i]);
if (!n || br.getNorth() > n) n = br.getNorth();
if (!e || br.getEast() > e) e = br.getEast();
if (!s || br.getSouth() < s) s = br.getSouth();
if (!w || br.getWest() < w) w = br.getWest();
}
map.setView({ bounds: Microsoft.Maps.LocationRect.fromEdges(n, w, s, e) });```

Wednesday, September 14, 2016 3:20 PM

• In Bing Maps V8, the spatial math library provides a function that makes it easy to generate a LocationRect from an array of shapes. Here is a code sample:

```//Load the spatial math library eary in your code.