Map tap event / mouse down event in windows phone 8?

女生的网名这么多〃 提交于 2019-12-31 01:57:08

问题


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.

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);
}

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?

Thank you very much.


回答1:


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);

instead.



来源:https://stackoverflow.com/questions/13716289/map-tap-event-mouse-down-event-in-windows-phone-8

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!