Windows Phone 8中的地图点击事件/鼠标按下事件? [英] Map tap event / mouse down event in windows phone 8?
问题描述
我正在使用Windows Phone仿真器.我写了一个非常简单的程序:当用户点击一次地图时在地图上绘制一个标记.
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.
我的代码有什么问题吗?
Is there anything wrong with my code?
非常感谢您.
推荐答案
GestureEventArgs.GetPosition()方法采用一个参数,该参数指定要获取相对于哪个UIElement的坐标(请参见
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屋!