# question

## How to zoom out a map to show all its elements (Pins, Circles, Polygons)?

As the title says, I want to be able to have all map components displayed on map. More importantly, I want to get the bounds of the map that has all components visible. This information needs to be saved in the backend so that when this information is accessed, the map can display correctly with all map components visible.

If I find the min Latitude and Longitude, and max Latitude and Longitude from all the (latitude, longitude) of the map components, and then draw the map bounded by them, will I get all components shown on the map?

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello,​

Welcome to our Microsoft Q&A platform!

Firstly, here are no api to achieve it, Following way is an idea of realization.

`customMap.MoveToRegion(MapSpan.FromCenterAndRadius(new Position(37.79752, -122.40183), Distance.FromMiles(1.0)));` we use this code to make sure the center point of map and radius.

Now you need how all its elements (Pins, Circles, Polygons), So you have to cacluate the center point from all of the Position. Then get the (longest distance )/2 from Latitude and Longitude. to set the `Distance.FromMiles(longest distance )/2))`.

You can try to following method to get the CentralPoint.

``````public static double[] CentralPoint(List<Position> points)
{
double[] centroid = { 0.0, 0.0 };

for (int i = 0; i < points.Count; i++)
{
centroid += points[i].Latitude;
centroid += points[i].Longitude;
}

int totalPoints = points.Count();
centroid = centroid / totalPoints;
centroid = centroid / totalPoints;

return centroid;
}``````

Here is get the distance from the point. We need to compare all of points. then get the Longest distance. then longest distance/2 = Radius

``````private double distance(double lat1, double lon1, double lat2, double lon2)
{
double theta = lon1 - lon2;
dist = Math.Acos(dist);
dist = dist * 60 * 1.1515;
return (dist);
}

{
return (deg * Math.PI / 180.0);
}

{
return (rad * 180.0 / Math.PI);
}``````

Best Regards,

Leon Lu

· 2

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

@Leon-Lu Thank you for the detailed answer. I have a question about the unit of the distance calculation. Is it kilometers or miles? What do the constants 60 and 1.1515 mean?

Also, is it possible to get the bounds of whatever is displaying on the screen, if not doing the calculations?