简体   繁体   中英

Bing Map on Windows Phone 8.1

I'm trying to change the viewport of a map within a Windows phone 8.1 app. I have to set the center (that it works) and the lowerLeft/upperRight coordinates to set the bounds of the map, but I have just the ZoomLevel property that can't help me to set the bounds of the map with precision.

This is what I have:

XAML

xmlns:Maps="using:Windows.UI.Xaml.Controls.Maps"
...
<Maps:MapControl x:Name="myMap" MapServiceToken="<token>"/>

CODE

this.myMap.Center = new Geopoint(new BasicGeoposition() { Latitude = 46.85, Longitude = 8.94});

Now I want to set the upperRight and lowerLeft corner to set the bounds. I saw this article HERE but it doesn't work for me.. the ConvertGeoCoordinateToViewportPoint doesn't exist with the namespace Windows.UI.Xaml.Controls.Maps and I don't know why.

Thank you.

You have a specific method to set the bounds of the current MapControl which is TrySetViewBoundsAsync , see:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/dn637065.aspx

And you might be interested in the GeoboundingBox class:

http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.devices.geolocation.geoboundingbox.aspx

And here is an example (Map is your MapControl):

List<BasicGeoposition> basicPositions = new List<BasicGeoposition>();
basicPositions.Add(new BasicGeoposition() { Latitude = 50, Longitude = 3 });
basicPositions.Add(new BasicGeoposition() { Latitude = 55, Longitude = 8 });
basicPositions.Add(new BasicGeoposition() { Latitude = 42, Longitude = 0 });

this.Map.TrySetViewBoundsAsync(GeoboundingBox.TryCompute(basicPositions), null, MapAnimationKind.Default);

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