的Windows Phone 8 - 在地图上显示方法文档当前位置 [英] Windows Phone 8 - HowTo display current position on the map
问题描述
正如标题建议我正在与地图上的用户的当前位置的显示struggeling。
据我所知有两种方式显示当前用户位置:
-
在代码:创建一个椭圆,将其设置为一个
MapOverlay
,设置MapOverlay的会有地理座标,这个添加叠加层到MapLayer <内容/ code>这添加到地图 - 但我不能访问
MapOverlay
了,因此我无法改变(更新)用户的位置。
有没有一种方法来更新用户的位置,而无需重新绘制所有图层? -
XAML和代码:在Windows Phone 7的,我能够加入
图钉
地图和让GeoCoordinateWatcher
处理PositionChanged
事件,并设置MyLocation.Location
到当前位置。
看来,有没有办法一个图钉
添加到地图中,如果你不使用的Windows Phone工具包。于是,我尝试添加图钉
从Windows Phone的工具包:
<预类=郎XML prettyprint-覆盖>
的xmlns:地图=CLR的命名空间:Microsoft.Phone.Maps.Controls;装配= Microsoft.Phone.Maps
的xmlns:maptk =clr-命名空间:Microsoft.Phone.Maps.Toolkit;装配= Microsoft.Phone.Controls.Toolkit
< maptk:图钉X:NAME =MyLocation>
< maptk:Pushpin.Template>
<&控件模板GT;
<椭圆
WIDTH =15
高度=15
保证金=0
填充=钢青
StrokeThickness = 1
行程=黑/>
< /控件模板>
< / maptk:Pushpin.Template>
< / maptk:图钉>
但我不能在我的MapPage.xaml访问MyLocation图钉(调试器说,这是空
)。
我可以显示与 maptk:图钉
在Windows Phone 7的,我可以简单地创建了图钉一个XAML布局,将保存用户位置像这样的:
<预类=郎咸平的XML prettyprint-覆盖>
的xmlns:地图=CLR的命名空间:Microsoft.Phone.Controls.Maps ;装配= Microsoft.Phone.Controls.Maps
<地图:地图Grid.Row =2×:NAME =地图>
<地图:图钉X:NAME =MyLocation>
<地图:Pushpin.Template>
<&控件模板GT;
将;椭圆宽度=12
高度=12
保证金=0
填充=钢青
StrokeThickness =1
行程=黑
/>
< /控件模板>
< /图:Pushpin.Template>
< /图:图钉>
< /地图:地图>
然后我可以添加一个 GeoCoordinateWatcher
这将监听 PositionChanged
事件,改变MyLocation图钉的位置
:
<预类=郎-CS prettyprint-覆盖>
无效GeoCoordinateWatcher_PositionChanged(对象发件人,GeoPositionChangedEventArgs<会有地理座标> E)
{
MyLocation.Location = e.Position。位置;
}
尝试这种方式,
图钉图钉=新图钉();
pushpin.Background =新的SolidColorBrush(Colors.Red);
pushpin.Location =新会有地理座标(经纬度);
pushpin.Content =SampleString;
pushpin.Width = 25;
map1.Children.Add(图钉); //这是的方式添加图钉映射
参观了这一点。
As the title suggest I am struggeling with the display of the current location of the user on the map.
Afaik there a two ways to display the current user location:
In Code: create a ellipse, set it as content of a
MapOverlay
, set the GeoCoordinate of the MapOverlay, add this overlay to aMapLayer
and add this to the map - but I cannot access theMapOverlay
anymore and thus I cannot change (update) the position of the user. Is there a way to update the user position without having to redraw all the map layers?XAML and Code: In Windows Phone 7 I was able to add a
Pushpin
to the map and let theGeoCoordinateWatcher
handle thePositionChanged
event and set theMyLocation.Location
to the current location.
It seems that there is no way to add a Pushpin
to the map if you don't use the Windows Phone Toolkit. So I tried to add Pushpin
from the Windows Phone Toolkit:
xmlns:maps="clr-namespace:Microsoft.Phone.Maps.Controls;assembly=Microsoft.Phone.Maps"
xmlns:maptk="clr-namespace:Microsoft.Phone.Maps.Toolkit;assembly=Microsoft.Phone.Controls.Toolkit"
<maptk:Pushpin x:Name="MyLocation">
<maptk:Pushpin.Template>
<ControlTemplate>
<Ellipse
Width="15"
Height="15"
Margin="0"
Fill="SteelBlue"
StrokeThickness="1"
Stroke="Black"/>
</ControlTemplate>
</maptk:Pushpin.Template>
</maptk:Pushpin>
But I cannot access the MyLocation pushpin in my MapPage.xaml (the debugger says it is null
).
Can I display and update the current user position on the map with maptk:Pushpin
?
In Windows Phone 7 I could simply create a XAML layout for the pushpin which would hold the user location like this:
xmlns:maps="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
<maps:Map Grid.Row="2" x:Name="Map" >
<maps:Pushpin x:Name="MyLocation" >
<maps:Pushpin.Template>
<ControlTemplate>
<Ellipse Width="12"
Height="12"
Margin="0"
Fill="SteelBlue"
StrokeThickness="1"
Stroke="Black"
/>
</ControlTemplate>
</maps:Pushpin.Template>
</maps:Pushpin>
</maps:Map>
then I could add a GeoCoordinateWatcher
which would listen for the PositionChanged
event and change the Location
of the MyLocation pushpin:
void GeoCoordinateWatcher_PositionChanged ( object sender, GeoPositionChangedEventArgs<GeoCoordinate> e )
{
MyLocation.Location = e.Position.Location;
}
try this way,
Pushpin pushpin = new Pushpin();
pushpin.Background = new SolidColorBrush(Colors.Red);
pushpin.Location = new GeoCoordinate(Latitude, Longitude);
pushpin.Content = "SampleString";
pushpin.Width = 25;
map1.Children.Add(pushpin);//this is way add pushpin to map
Have visited this one .
这篇关于的Windows Phone 8 - 在地图上显示方法文档当前位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!