0

我在地图中显示图钉。

 void GeoPositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
        {
            _pushpins.Clear();
            var cor = new GeoCoordinate(e.Position.Location.Latitude, e.Position.Location.Longitude);
            //Using the current coordinates define the Map center to those coordinates.
            map.Center = cor;
            _pushpins.Add(new PushpinModel
            {

                Description = "test",
                Name = "test",
                Location = new GeoCoordinate(e.Position.Location.Latitude,
                                                e.Position.Location.Longitude),
                DatetimeAdded = DateTime.Now
            });

            map.ZoomLevel = 15;


        }

对于图钉加载需要一些时间,因为图钉正在移动到地图中的当前位置。在那个时候,只要单击图钉给出“NULL 引用异常”。请告诉我如何处理?

编辑:

 private void Pushpin_Tap(object sender,
        System.Windows.Input.GestureEventArgs e)
        {
            var _ppmodel = sender as Pushpin;
            Pushpin pin = sender as Pushpin;

             _id = _ppmodel.Tag.ToString();

            ContextMenu contextMenu =
                ContextMenuService.GetContextMenu(_ppmodel);

            contextMenu.DataContext = _pushpins.Where
                (c => (c.Location
                    == _ppmodel.Location)).FirstOrDefault();
            if (contextMenu.Parent == null)
            {
                contextMenu.IsOpen = true;
            }
        }

虽然图钉点击有时会出现空引用异常......

4

0 回答 0