Windows Phone 8, 添加Map控件
摘要:
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 = ; // Create a small circle to mark the current location.
Ellipse myCircle = new Ellipse();
myCircle.Fill = new SolidColorBrush(Colors.Blue);
myCircle.Height = ;
myCircle.Width = ;
myCircle.Opacity = ;
// 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 8, 添加Map控件的更多相关文章
- 如何添加地图控件到Windows Phone 8的页面中
原文 如何添加地图控件到Windows Phone 8的页面中 本主题介绍了各种方法来添加一个地图控件到Windows Phone 8的项目.该地图控件在Windows Phone的SDK 8.0的库 ...
- 移动UI控件Telerik UI for Xamarin发布R2 2019|引入Map控件
Telerik UI for Xamarin是一个构建跨平台移动应用程序的原生UI.Telerik UI for Xamarin使用Xamarin.Forms技术,它可以让开发人员从一个单一的共享C# ...
- 与众不同 windows phone (2) - Control(控件)
原文:与众不同 windows phone (2) - Control(控件) [索引页][源码下载] 与众不同 windows phone (2) - Control(控件) 作者:webabcd介 ...
- Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看。
原文:Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看. 现在很多App都用到了Pivot视图 来当作 整个App主页面.如果你的Pivot视图主页面承载了大量数据的 ...
- 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView
原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...
- 重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter
原文:重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresente ...
- 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup
原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...
- C# windows服务:C#windows服务中的Timer控件的使用
C# windows服务程序中的Timer控件的使用问题是如何解决的呢? 今天和同事一起研究了下C# windows服务程序中的Timer控件的使用的写法. 我们在建立一个C# windows服务程序 ...
- Visual Studio 2008 添加MScomm控件的方法
1.下载MSCOMM.zip,解压后包含4个文件:MSCOMM32.OCX, MSCOMM.SRG, MSCOMM32.DEP, MSCOMM32.OCA 2.将Mscomm.srg, Mscomm3 ...
随机推荐
- SQL实现新增表,表名更改,列名更改,约束更改等
--新建表: CREATE TABLE TABLENAME ( ID INT IDENTITY (1,1) PRIMARY KEY , NAME VARCHAR(50) DEFAULT 'HELLO' ...
- webdriver 的三种等待方式
1.显式等待 一个显式等待是你定义的一段代码,用于等待某个条件发生然后再继续执行后续代码. from selenium import webdriverfrom selenium.webdriver ...
- [源][osg][osgBullet]osgBullet例子介绍
1.BasicDemo 基本样例 一个小玩具飞机坠落,一个立方体盒子在转圈 2.centerofmass 质心 3.collision 碰撞检测 这里有一个大神自己改的例子: http://blog. ...
- 修改unity变量名但不丢失序列化值
using UnityEngine; using UnityEngine.Serialization; public class LgsTest : MonoBehaviour { [Formerly ...
- C#中正确使用enum做Key的姿势
C#中自定义enum,然后将其作为Dictionary的Key,通常的做法如下: using System; using System.Text; using System.Collections.G ...
- TimeZone 时区 (JS .NET JSON MYSQL) + work week 闰年
来源参考 : http://www.cnblogs.com/qiuyi21/archive/2008/03/04/1089456.html 来源参考 : http://walkingice.blogs ...
- Jaccard similarity(杰卡德相似度)和Abundance correlation(丰度相关性)
杰卡德距离(Jaccard Distance) 是用来衡量两个集合差异性的一种指标,它是杰卡德相似系数的补集,被定义为1减去Jaccard相似系数.而杰卡德相似系数(Jaccard similarit ...
- python-day30--粘包
一. 什么是粘包 1.须知:只有TCP有粘包现象,UDP永远不会粘包 2.所谓粘包问题主要还是因为接收方不知道消息之间的界限,不知道一次性提取多少字节的数据所造成的. 二.两种情况下会发生粘包. 1. ...
- 带分数(dfs,next_permutation)
问题描述 100 可以表示为带分数的形式:100 = 3 + 69258 / 714. 还可以表示为:100 = 82 + 3546 / 197. 注意特征:带分数中,数字1~9分别出现且只出现一次( ...
- Mac XMind8 保存时报错
错误提示 截图 日志 查看错误日志的方式:打开xmind –> 关于xmind –> 安装细节 –> 选项卡 “配置” –> 查看错误日志 看到有Caused by: org. ...