Windows Phone 8, 添加Map控件
2013-08-07 08:27
190 查看
摘要:
1. 添加Map控件到程序。
2. 在Map控件中显示您当前的位置。
内容:
首先在WMAppManifest.xml中的Capabilities选项卡中勾选如下两项:ID_CAP_MAP, ID_CAP_LOCATION
在XAML中添加Map控件:
在后台代码中, 添加Convert 类使能从Windows.Devices.Geolocation; 转换到 System.Device.Location;
添加如下命名空间:
代码实例:
参考: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735578(v=vs.105).aspx
1. 添加Map控件到程序。
2. 在Map控件中显示您当前的位置。
内容:
首先在WMAppManifest.xml中的Capabilities选项卡中勾选如下两项:ID_CAP_MAP, ID_CAP_LOCATION
在XAML中添加Map控件:
<!--ContentPanel - place additional content here--> <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0"> <Controls:Map x:Name="mapWithMyLocation" /> </Grid>
在后台代码中, 添加Convert 类使能从Windows.Devices.Geolocation; 转换到 System.Device.Location;
public static class CoordinateConverter { public static GeoCoordinate ConvertGeocoordinate(Geocoordinate geocoordinate) { return new GeoCoordinate ( geocoordinate.Latitude, geocoordinate.Longitude, geocoordinate.Altitude ?? Double.NaN, geocoordinate.Accuracy, geocoordinate.AltitudeAccuracy ?? Double.NaN, geocoordinate.Speed ?? Double.NaN, geocoordinate.Heading ?? Double.NaN ); } }
添加如下命名空间:
using System.Device.Location; using Windows.Devices.Geolocation; using System.Windows.Shapes; using System.Windows.Media; using Microsoft.Phone.Maps.Controls;
代码实例:
public partial class MainPage : PhoneApplicationPage { // Constructor public MainPage() { InitializeComponent(); // Sample code to localize the ApplicationBar //BuildLocalizedApplicationBar(); } protected override void OnNavigatedTo(NavigationEventArgs e) { ShowMyLocationOntheMap(); base.OnNavigatedTo(e); } private async void ShowMyLocationOntheMap() { Geolocator myGeolocator = new Geolocator(); Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync(); Geocoordinate myGeocoordinate = myGeoposition.Coordinate; GeoCoordinate myGeoCoordinate1 = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate); mapWithMyLocation.Center = myGeoCoordinate1; mapWithMyLocation.ZoomLevel = 17; // Create a small circle to mark the current location. Ellipse myCircle = new Ellipse(); myCircle.Fill = new SolidColorBrush(Colors.Blue); 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 = myGeoCoordinate1; // Create a MapLayer to contain the MapOverlay. MapLayer myLocationLayer = new MapLayer(); myLocationLayer.Add(myLocationOverlay); // Add the MapLayer to the Map. mapWithMyLocation.Layers.Add(myLocationLayer); } }
参考: http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj735578(v=vs.105).aspx
相关文章推荐
- Windows Phone开发之 Map控件
- Windows Phone 7 常用控件之Map
- Windows Phone 7 中BingMap控件的使用
- Windows Phone 7 Silverlight控件之--Map入门
- 如何将地图控件添加到 Windows Phone 8 中的页面中
- Windows Phone 7 编程实践—捕获Map控件的DoubleTap事件
- Windows Phone 7 Silverlight控件之--Map的基本控制
- Windows Phone中Map控件由浅及深
- AE二次开发,选择本地shp文件添加到AxMapControl控件中
- 在MapView上面添加浮动控件的方法
- 如何添加地图控件到Windows Phone 8的页面中
- 用户控件及事件添加
- JS动态添加删除控件
- VC++6.0中MFC图片控件无法利用类向导添加成员变量的解决
- Android RecyclerView item动态添加控件重复问题
- Windows Phone 8.1 列表控件(1):基本
- Static控件添加Tooltip
- C#--操作DataGridView控件详解(数据显示,更改行高行宽,交换行,自动添加行号)
- MFC 树控件 如何为二级节点动态地添加三、四级节点
- 优酷来疯直播安卓控件,支持flv、rtmp,支持添加视频特效等等