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 ...
随机推荐
- JavaScript页面跳转的一些实现方法
第一种 <script language=”javascript” type=”text/javascript”> window.location.href=”login.jsp?back ...
- django视图函数及快捷方式
视图函数,简称视图,本质上是一个简单的Python函数,它接受Web请求并且返回Web响应. 响应的内容可以是HTML网页.重定向.404错误,XML文档或图像等任何东西.但是,无论视图本身是个什么处 ...
- 深入Animation,在SurfaceView中照样使用Android—Tween Animation!
第一类:Frame By Frame 帧动画( 不推荐游戏开发中使用) 所谓帧动画,就是顺序播放事先做好的图像,类似于放电影: 分析: 此种方式类似我之 ...
- 多年未写过java了
java面试必须了解和记忆的知识点(linux,nginx,数据库之类的暂时不考虑了) java面试的115常见问题,这个博客还是不过的推荐一下吧 http://www.importnew.com/1 ...
- table maker's delimma
table maker's delimma是计算机浮点数精度的一个问题. 浮点数的表示方式 计算机能表示的数字都是有理数,所有的有理数都可以归结为下面的模式:1.@@@ × 2#### 其中,@@@ ...
- 肠道型(enterotype)简介
An enterotype is a classification of living organisms based on its bacteriological ecosystem in the ...
- wacher和acl
一.wacher 问题 1.集群中有多个机器,当某个通用的配置发生变化 ,怎么让所有服务器的配置都统一生效? 2.当某个集群节点宕机,其它节点怎么知道? Zk中引入 ...
- JS-Object(3) 继承(prototype方式, 类方式); javascript6的知识(部分)
原型方式的继承 创建child object classes(constructors) , 子类如何从父类中继承特性. 原型链继承prototypal inheritance (ruby中的继承也是 ...
- nyoj737石子合并(一)
先得出区间为1和2时的结果.用arr[i][j]记录i,j内的和.dp[i][j]记录i,j区间全加起来的最小花费.那么区间大小为1和2时都是明显的.为3时枚举断点.其中一个区间大小为1也是可行的. ...
- 在 Confluence 6 中的 Jira 权限
只读(Read Only) 从你 JIRA 应用服务器上取得的用户,用户组和用户组成员.这些用户的信息只能通过你的 JIRA 服务器进行修改. https://www.cwiki.us/display ...