0

我正在开发一个 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>
4

1 回答 1

2

您想在 Windows Phone 8 应用程序中使用 Bing 地图吗?我在 WP8 应用程序中使用旧的 Bing 地图控件时遇到问题。我写了关于它的 windows phone 8 old map vs new map。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>

//初始化图钉

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

在 windows phone 8 应用程序中查看您的代码图钉位置绑定不起作用

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;
    });
}
于 2013-09-30T10:44:05.880 回答