简体   繁体   中英

Windows Phone 8 Map control - how to get map bounds

I'm using the brand new Windows Phone 8 Map control, but have run into an issue: I need to get the LocationRectangle of the map's bounds, in other words the Latitude span and Longitude span.

With the Bing Maps control, you can just do:

 LocationRect bounds = map.Bounds;

...however, there seems to be no relevant fields in this new control. Can anyone help, or do I need to reverse engineer the various Zoom Levels and work it out based on the center point, Zoom Level and pixel height/width ?

You can use the viewport convert methods, like:

GeoCoordinate topLeft = yourMapInstance.ConvertViewportPointToGeoCoordinate(new Point(0, 0));
GeoCoordinate bottomRight = 
yourMapInstance.ConvertViewportPointToGeoCoordinate(new Point(mapSize.Width, mapSize.Height));

return LocationRectangle.CreateBoundingRectangle(new[] { topLeft, bottomRight });

Probably you can directly use the renderSize of the mapControl instance, but to be sure about the right dimensions on runtime, i would suggest to listen for the "SizeChanged" event. And checking the mapsize values not to be 0 or Infiniteis probably also a good idea.

Just to be clear you can still use the original Bing Maps in WP8 (although they have been deprecated), if you have already large app created for WP7.
You can find the library with Bing Maps for WP8 here:

C:\\Program Files (x86)\\Microsoft SDKs\\Windows Phone\\v8.0\\Libraries

Is this a feasible solution for you, or you want to switch to the new maps anyway?

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