Search code examples
gpscoordinateszoomingbing-mapscoordinate-transformation

Is there a way to programmatically determine the optimal Bing Maps Zoom Level based on an array of GPS Coordinates?


When programmatically adding an array of GPS Coordinates to a Bing Map, I want to set the Zoom level to the optimal - to show every pushpin/location, but "just barely."

I imagine a way to do this would be to identify the furthest points in the cardinal directions found within the array of coordinates, and then calculate how many miles you need to display both east-to-west and north-to-south.

For example, let's say the furthest north and furthest south locations are determined to be forty miles distant from each other, and the furthest east and furthest west locations are determined to be sixty miles apart from each other. Is there a rule of thumb/calculation/algorithm that would determine what the most "zoomed-in" level would be that would display all of the locations/coordinates, with the "outliers" being as close to the edge of the displayed portion of the map as possible?


Solution

  • You can set a map view with a bounding box, which will automatically determine the zoom level. See the example here https://www.bing.com/api/maps/sdkrelease/mapcontrol/isdk/setmapviewoptions using the Bounds property as documented here https://learn.microsoft.com/en-us/bingmaps/v8-web-control/map-control-api/viewoptions-object