简体   繁体   中英

Zoom to show all locations in bing maps

Say I have 3 pushpins: (1) California, (2) Florida, (3) New York. In order for all the 3 of them to be visible, I'd have to zoom out far enough to pretty much see the whole country. But say instead of that I had (1) California, (2) Nevada, (3) Texas. I'd have to zoom out only to cover the south west corner of the US. Is there any function in the bing maps for Windows Phone 7 API that helps me with this. Basically, I want to zoom out just enough to see a set of locations.

Thanks!

Yes. it is possible. CurrentItems is source for my map.

var locations = CurrentItems.Select(model => model.Location);
map.SetView(LocationRect.CreateLocationRect(locations));

I don't know about a function that will do what you want directly, but you can find the bounding box that just surrounds all of your locations and you should be able to set the viewport to that extent.

If you start with an inverted box where the bottom left corner is (maxVal, maxVal) and the top right is (-maxVal, -maxval) . you can loop over all your points and reset the bottom left if the point is less than its current value or the top right if it's greater than its current value.

The end result will be the smallest box that everything fits into. Add a little to the size to cope with rounding error and to make sure your pins are actually on the map and then set the extent of the viewport.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM