Windows Phone 8 中的地图点击事件/鼠标按下事件? [英] Map tap event / mouse down event in windows phone 8?
问题描述
我正在使用 Windows 手机模拟器.我写了一个非常简单的程序:当用户点击地图一次时,在地图上绘制一个标记.
I am using the windows phone emulator. I wrote a very simple program: draw a marker on the map when the user tap the map once.
然后我使用了 map_tap 事件,得到了点击的位置如下,
Then I used map_tap event, and get the tapped location as follows,
private void map_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
Point p = e.GetPosition(null);
GeoCoordinate s = map.ConvertViewportPointToGeoCoordinate(p);
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0, 0);
myLocationOverlay.GeoCoordinate = s;
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
map.Layers.Add(myLocationLayer);
}
问题是,我得到的点不是鼠标(在模拟器中是鼠标而不是手指)点击的点.它比我点击的位置低一些(大约低 50 像素).
The problem is that, the point I get is not the point where the mouse (in the emulator it is a mouse but not a finger) clicked. It is some distance lower (about 50 pixels lower) than where I clicked.
所以无论我在模拟器中点击哪里,都会在我点击的地方下方绘制圆圈,这有点奇怪.
So wherever I click in the emulator, the circle is drawn below where I clicked, it's some kind of weird.
我的代码有问题吗?
非常感谢.
推荐答案
GestureEventArgs.GetPosition() 方法接受一个参数,指定要获取相对于哪个 UIElement 的坐标(请参阅 MSDN 文档).所以,尝试做
The GestureEventArgs.GetPosition() method takes a parameter specifying what UIElement to get the coordinate relative to (see the MSDN documentation). So, try doing
Point p = e.GetPosition(map);
相反.
这篇关于Windows Phone 8 中的地图点击事件/鼠标按下事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!