Reputation: 229
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.
Upvotes: 1
Views: 2671
Reputation: 2952
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:
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);
Upvotes: 5