如何在 Windows Phone 应用地图上的当前位置添加标记
How to add marker at current location on a Windows Phone App Map
首先,我是 Windows Phone 开发人员的新手,所以我可能会漏掉一些明显的东西。
我的 xaml 中有一个 ControlMap,我正在尝试在当前位置添加标记。我浏览了很多教程,但我不能只找到已弃用的方法(大量使用无效)来做到这一点,虽然乍一看似乎很简单,但我根本无法让它发挥作用。
xaml中的地图:
<Maps:MapControl x:Name="LocateMap" Height="221" Margin="0,0,-0.167,0"/>
我应该在 .cs 中做什么来添加这个标记?在哪里?
目的是稍后存储它,然后在应用程序启动所有旧标记 + 实际位置标记时打印。
如果您想在特定位置(纬度、经度)设置图钉,请执行以下步骤。
//setting the Map center
LocateMap.Center = CurrentLocation = new System.Device.Location.GeoCoordinate(lat, lon);
// Create a small circle to mark the current location.
Ellipse myCircle = new Ellipse();
myCircle.Fill = App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
// Create a MapOverlay to contain the circle.
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new System.Device.Location.GeoCoordinate(lat,
lon);
// Create a MapLayer to contain the MapOverlay.
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
//adding map layer to the map
LocateMap.Layers.Add(myLocationLayer);
首先,我是 Windows Phone 开发人员的新手,所以我可能会漏掉一些明显的东西。 我的 xaml 中有一个 ControlMap,我正在尝试在当前位置添加标记。我浏览了很多教程,但我不能只找到已弃用的方法(大量使用无效)来做到这一点,虽然乍一看似乎很简单,但我根本无法让它发挥作用。
xaml中的地图:
<Maps:MapControl x:Name="LocateMap" Height="221" Margin="0,0,-0.167,0"/>
我应该在 .cs 中做什么来添加这个标记?在哪里? 目的是稍后存储它,然后在应用程序启动所有旧标记 + 实际位置标记时打印。
如果您想在特定位置(纬度、经度)设置图钉,请执行以下步骤。
//setting the Map center
LocateMap.Center = CurrentLocation = new System.Device.Location.GeoCoordinate(lat, lon);
// Create a small circle to mark the current location.
Ellipse myCircle = new Ellipse();
myCircle.Fill = App.Current.Resources["PhoneAccentBrush"] as SolidColorBrush;
myCircle.Height = 20;
myCircle.Width = 20;
myCircle.Opacity = 50;
// Create a MapOverlay to contain the circle.
MapOverlay myLocationOverlay = new MapOverlay();
myLocationOverlay.Content = myCircle;
myLocationOverlay.PositionOrigin = new Point(0.5, 0.5);
myLocationOverlay.GeoCoordinate = new System.Device.Location.GeoCoordinate(lat,
lon);
// Create a MapLayer to contain the MapOverlay.
MapLayer myLocationLayer = new MapLayer();
myLocationLayer.Add(myLocationOverlay);
//adding map layer to the map
LocateMap.Layers.Add(myLocationLayer);