Phone 7 Bing地图控件 - 点按时添加图钉

Yar*_*evi 5 bing-maps pushpin windows-phone-7

我正在使用最新的Phone 7 RTM工具(今天下载,2010年10月7日).

我想在这里做一件简单的事情:

当用户在地图控件上点击一次时,我想在那里放一个图钉.另外,我想保持地图控件的常规内置行为(点击两次以缩放).

(如果不能保持这两种行为,那么可能需要长时间按下地图才能放置图钉).

在尝试解决这个问题时,我遇到了有关Phone7控件地图所做更改的文档:http: //msdn.microsoft.com/en-us/library/ff955762.aspx

然后我看到了新类MapInputEventArgs,它有一个ViewportPoint成员.

在查看常规SilverLight地图控件上的代码示例时,我看到如下所示:

private void OnMouseClick(object sender, MapMouseEventArgs e)
    {
        Point clickLocation = e.ViewportPoint;
        Location location = x_Map.ViewportPointToLocation(clickLocation);

        Pushpin pushpin = new Pushpin(); 
        m_PushpinLayer.AddChild(pushpin, new Location(latitude, longitude));
    }
Run Code Online (Sandbox Code Playgroud)

但在Phone7的情况下,我找不到合适的事件处理程序,我找不到谁在地图控件中使用MapInputEventArgs.在谷歌搜索它只获得1个结果!

那么,"点击一次"的适当事件在哪里,以及如何在此事件被触发后获得ViewportPoint?

提前致谢.

小智 6

如果你还有问题,那就搞清楚了.

MouseLeftButtonUp和MouseLeftButtonDown事件有一个GetPosition方法,它将返回您要查找的点

 private void MapMain_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
    {

        Point p = e.GetPosition(this.MapMain);
        GeoCoordinate geo = new GeoCoordinate();
        geo = MapMain.ViewportPointToLocation(p);
        MapMain.ZoomLevel = 17;
        MapMain.Center = geo;
        //---create a new pushpin---
        Pushpin pin = new Pushpin();

        //---set the location for the pushpin---
        pin.Location = geo;

        //---add the pushpin to the map---
        MapMain.Children.Add(pin);
    }
Run Code Online (Sandbox Code Playgroud)