在MapControl Tap事件上添加图钉

时间:2012-07-13 12:45:44

标签: silverlight windows-phone-7 map geolocation

我正在尝试在Tap上添加一个图钉到我的MapControl。我面临的问题是,GestureEventArgs传递了Map相对坐标,例如:

X = 216
Y = 197

由于这个原因,我无法在图钉上指定要添加到地图中的合作伙伴。这正是我正在做的事情。

private void MainMap_Tap(object sender, GestureEventArgs e)
    {
        Point p = e.GetPosition(this.MainMap);
        GeoCoordinate g = new GeoCoordinate();
        g = MainMap.ViewportPointToLocation(p);

        MyPin.Location = g;
        MainMap.Children.Add(MyPin);
    }

我的代码因MyPin.Location = g处的空引用错误而中断。在g中我得到像

这样的值
g = {-0.00446319579627641, 0.00369071960449219}

1 个答案:

答案 0 :(得分:2)

可能是因为你的MyPin没有初始化。

如果图钉的位置为空,则无法设置图钉的位置。

http://msdn.microsoft.com/en-us/library/gg588563(v=vs.92

相关问题