gpt4 book ai didi

c# - WPF Bing map 将图钉放置在不正确的位置

转载 作者:太空宇宙 更新时间:2023-11-03 21:23:52 25 4
gpt4 key购买 nike

我已按照 https://msdn.microsoft.com/en-GB/library/hh709044.aspx 上的教程进行操作了解如何在 map 上放置图钉。

除引脚始终位于我的鼠标指针下方约 3 厘米外,一切正常。

我不确定我做错了什么。

这是我的 xaml 代码

            <Grid HorizontalAlignment="Stretch" Margin="6,6,6,6" Name="gpsGrid" VerticalAlignment="Stretch">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Label Name="latitudeLabel" Content="Latitude: " Grid.Row="0" Grid.Column="0"/>
<Label Name="longitudeLabel" Content="Longitude: " Grid.Row="1" Grid.Column="0"/>
<Label Name="altitudeLabel" Content="Altitude: " Grid.Row="2" Grid.Column="0"/>
<Label Name="courseLabel" Content="Course: " Grid.Row="3" Grid.Column="0"/>
<Label Name="speedLabel" Content="Speed: " Grid.Row="4" Grid.Column="0"/>
<Label Name="gpsConnectedLabel" Content="Connected: " Grid.Row="5" Grid.Column="0"/>
<m:Map CredentialsProvider="XXXXXXXXXXXXXXXXXXXXXX" Center="53.7997,-1.5492" ZoomLevel="16" Mode="Aerial" x:Name="Map" MouseDoubleClick="MapWithPushpins_MouseDoubleClick" Grid.Row="6" Grid.Column="0"/>
</Grid>

和我的点击处理程序

            private void MapWithPushpins_MouseDoubleClick(object sender, MouseButtonEventArgs e)
{
// Disables the default mouse double-click action.
e.Handled = true;

//Get the mouse click coordinates
Point mousePosition = e.GetPosition(this);

//Convert the mouse coordinates to a locatoin on the map
Location pinLocation = Map.ViewportPointToLocation(mousePosition);

// The pushpin to add to the map.
Pushpin pin = new Pushpin();
pin.Location = pinLocation;

// Adds the pushpin to the map.
Map.Children.Add(pin);
}

知道为什么我的图钉没有放在正确的位置吗?

谢谢乔

最佳答案

您必须获取相对于 map 控件的视口(viewport)点,而不是声明 MapWithPushpins_MouseDoubleClick 方法的 Window 或 UserControl。

将传递给 GetPosition 的参数从 this 更改为 Map:

var mousePosition = e.GetPosition(Map);

或者到 sender 参数,它也引用了 map 控件:

var mousePosition = e.GetPosition((UIElement)sender);

关于c# - WPF Bing map 将图钉放置在不正确的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28696290/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com