Windows phone 8 在windows phone 8应用程序中绑定地图中心和图钉

Windows phone 8 在windows phone 8应用程序中绑定地图中心和图钉,windows-phone-8,mvvm,bing-maps,Windows Phone 8,Mvvm,Bing Maps,我正在开发windows phone 8应用程序,我必须使用图钉实现地图控件,该图钉将显示用户的当前位置,我正在为图钉指定当前位置,现在我希望该图钉位于地图的中心。有人能帮我把图钉系在地图的中心吗 <maps:Map x:Name="MyMap" Center="{Binding}" ZoomLevel="15"> <toolkit:MapExtensions.Children> <toolkit:Pushpin x:Name

我正在开发windows phone 8应用程序,我必须使用图钉实现地图控件,该图钉将显示用户的当前位置,我正在为图钉指定当前位置,现在我希望该图钉位于地图的中心。有人能帮我把图钉系在地图的中心吗

<maps:Map x:Name="MyMap" Center="{Binding}" ZoomLevel="15">
        <toolkit:MapExtensions.Children>
            <toolkit:Pushpin x:Name="pushpin1" GeoCoordinate="{Binding}">
                <toolkit:Pushpin.Template>
                    <ControlTemplate TargetType="toolkit:Pushpin">
                        <StackPanel>
                            <ContentPresenter x:Name="content" Content="{TemplateBinding Content}" HorizontalAlignment="Left"></ContentPresenter>
                            <Path Data="M0,0L1,1L2,0L2,0L1,0L0,0Z"
                              Fill="#00AAFF"
                              Stretch="Fill"
                              Margin="-2,0"
                              Height="120"
                              Width="30"
                              Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Content.Visibility, Mode=TwoWay}"
                              HorizontalAlignment="Left"
                              />

                        </StackPanel>
                    </ControlTemplate>
                </toolkit:Pushpin.Template>
            </toolkit:Pushpin>
        </toolkit:MapExtensions.Children>
    </maps:Map>

您想在Windows Phone 8应用程序中使用Bing地图吗?我在WP8应用程序中使用旧的Bing地图控件时遇到问题。我写过。WP 8的最佳解决方案是新的诺基亚地图控件

在XAML中:

 xmlns:nokiamap="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
    xmlns:toolkit="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"

<nokiamap:Map Name="NokiaMap">
 <toolkit:MapExtensions.Children>
    <toolkit:Pushpin x:Name="MyPushpin"/>
 </toolkit:MapExtensions.Children>
</nokiamap:Map>
查看您的代码

void geologicator\u PositionChanged(地理定位发送器,PositionChangedEventArgs参数)
{
Dispatcher.BeginInvoke(()=>
{
ObservableCollection children=MapExtensions.GetChildren(MyMap);
var pin=children.FirstOrDefault(x=>x.GetType()==typeof(Pushpin))作为Pushpin;
pin.DataContext=args.Position.Coordinate;
//无装订
//pin.geocordinate=args.Position.Coordinate;
});
}

请提供您的代码,并更具体地说明错误是什么。除非您提供更多详细信息,否则我们无法真正帮助您。@Subby:请提供更好的解决方案。我认为ObservableCollection children=MapExtensions.GetChildren(诺基亚地图);var pin=children.FirstOrDefault(x=>x.GetType()==typeof(Pushpin))作为Pushpin;我的图钉=图钉;代码pushpin1.DataContext=args.Position.Coordinate中的bing映射帮助;不,你不能在MapExtensions中使用图钉。孩子们,用这种方式,你能纠正我在
private Pushpin MyPushpin { get; set; }

ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(NokiaMap);       
    var pin = children.FirstOrDefault(x => x.GetType() == typeof(Pushpin)) as Pushpin;
    MyPushpin = pin;
  public void StartGeolocator()
        {
              Geolocator geolocator = new Geolocator();
                geolocator.DesiredAccuracy = PositionAccuracy.High;
                geolocator.MovementThreshold = 10; 
                geolocator.PositionChanged += geolocator_PositionChanged;
                geolocator.StatusChanged += geolocator_StatusChanged;
            }
        }

 private void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
    {
       myGeoposition = new GeoCoordinate()
       {
            Latitude = args.Position.Coordinate.Latitude,
            Longitude = args.Position.Coordinate.Longitude,
       }
       MyPushpin.GeoCoordinate = myGeoposition;
       NokiaMap.SetView(myGeoposition, NokiaMap.ZoomLevel);
    }
void geolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs args)
{
    Dispatcher.BeginInvoke(() =>
    {
        ObservableCollection<DependencyObject> children = MapExtensions.GetChildren(MyMap);       
        var pin = children.FirstOrDefault(x => x.GetType() == typeof(Pushpin)) as Pushpin;        
        pin.DataContext = args.Position.Coordinate;
        //witout binding 
        //pin.GeoCoordinate = args.Position.Coordinate;
    });
}