SetView在Windows Phone中映射所需的位置、边距和中心点

本文关键字:位置 中心点 Windows Phone 映射 SetView | 更新日期: 2023-09-27 18:28:00

我在Windows Phone 8应用程序中添加了一个地图。现在我想要的是在地图上用一个中心点来查看一个想要的点。

XAML:

<Grid x:Name="ContentPanel" Grid.RowSpan="2">
            <Grid.RowDefinitions>
                <RowDefinition Height="68" />
                <RowDefinition Height="1" />
                <RowDefinition Height="65" />
                <RowDefinition Height="1" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
 <maps:Map x:Name="map"
                      Grid.RowSpan="5"
                          Height="800" />
<Image Source="/Assets/Images/Pin.png" Width="35" Height="55" 
                   VerticalAlignment="Center" HorizontalAlignment="Center"
                    Grid.RowSpan="5"
                   Canvas.ZIndex="15"/>
<Button Grid.Row="0" Content="Search" />
<Button Grid.Row="4" Content="Check" />
</Grid>

查看模型C#

MapRectLocation zoomLocation = new MapRectLocation();
                        zoomLocation.CenterPoint = new Location() { lat = CenterLocation.Latitude, lng = CenterLocation.Longitude };
                        zoomLocation.Locationx = new Location();
                        zoomLocation.Locationx.Latitude = FirstLocation.Latitude;
                        zoomLocation.Locationx.Longitude= FirstLocation.Longitude;
                        // Calculate the other point for boundary
                        zoomLocation.Locationy= GetEqivalentPoint(CenterLocation, FirstLocation);
public Location GetEqivalentPoint(System.Device.Location.GeoCoordinate CenterLocation, Location location)
        {
            var dlat = CenterLocation.Latitude - location.lat;
            var dlng = CenterLocation.Longitude - location.lng;
            Location equiPoint = new Location();
            equiPoint.lat = CenterLocation.Latitude + dlat;
            equiPoint.lng = CenterLocation.Longitude + dlng;
            return equiPoint;
        }

XAML.cs代码:

List<GeoCoordinate> zoomBoundaries = new List<GeoCoordinate>();
                    zoomBoundaries.Add(new GeoCoordinate(mapViewLocation.Locationx.lat, mapViewLocation.Locationx.lng));
                    zoomBoundaries.Add(new GeoCoordinate(mapViewLocation.Locationy.lat, mapViewLocation.Locationy.lng));
                    map.SetView(LocationRectangle.CreateBoundingRectangle(zoomBoundaries), new Thickness(0, 150, 0, 300));

地图设置为所需的缩放级别以显示该点,但问题是它没有保持与以前相同的中心点。我想保持中心位置不变,并在地图上显示FirstLocation点。我还在Setview中设置边距,以便将First位置点保持在XAML代码覆盖映射中的2个按钮上方。

请让我知道如何纠正这个问题?

SetView在Windows Phone中映射所需的位置、边距和中心点

试试这个:

    void SetLoc()
    {
        MyMap.Layers.Clear();
        try
        {
            // ... get the coordinates "myGeoCoordinate" 
            // Make my current location the center of the Map.
            this.MyMap.Center = myGeoCoordinate;
            this.MyMap.ZoomLevel = 12;
            // Create a small circle to mark the current location.
            Ellipse myCircle = new Ellipse();
            myCircle.Fill = new SolidColorBrush(Colors.Blue);
            myCircle.Height = 20;
            myCircle.Width = 20;
            myCircle.Opacity = 50;
            // Create a MapOverlay to contain the circle.
            MapOverlay myLocationOverlay = new MapOverlay();
            myLocationOverlay.Content = myCircle;
            myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
            myLocationOverlay.GeoCoordinate = myGeoCoordinate;
            // Create a MapLayer to contain the MapOverlay.
            MapLayer myLocationLayer = new MapLayer();
            myLocationLayer.Add(myLocationOverlay);
            // Add the MapLayer to the Map.
            MyMap.Layers.Add(myLocationLayer);
        }
        catch
        {
        }
    }