摘要:

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控件的更多相关文章

  1. 如何添加地图控件到Windows Phone 8的页面中

    原文 如何添加地图控件到Windows Phone 8的页面中 本主题介绍了各种方法来添加一个地图控件到Windows Phone 8的项目.该地图控件在Windows Phone的SDK 8.0的库 ...

  2. 移动UI控件Telerik UI for Xamarin发布R2 2019|引入Map控件

    Telerik UI for Xamarin是一个构建跨平台移动应用程序的原生UI.Telerik UI for Xamarin使用Xamarin.Forms技术,它可以让开发人员从一个单一的共享C# ...

  3. 与众不同 windows phone (2) - Control(控件)

    原文:与众不同 windows phone (2) - Control(控件) [索引页][源码下载] 与众不同 windows phone (2) - Control(控件) 作者:webabcd介 ...

  4. Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看。

    原文:Windows Phone 如果你把Pivot控件当成主页面,那么这篇文章你值得看. 现在很多App都用到了Pivot视图 来当作 整个App主页面.如果你的Pivot视图主页面承载了大量数据的 ...

  5. 重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView

    原文:重新想象 Windows 8 Store Apps (11) - 控件之 ListView 和 GridView [源码下载] 重新想象 Windows 8 Store Apps (11) - ...

  6. 重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresenter

    原文:重新想象 Windows 8 Store Apps (5) - 控件之集合控件: ComboBox, ListBox, FlipView, ItemsControl, ItemsPresente ...

  7. 重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter; 容器控件: Border, Viewbox, Popup

    原文:重新想象 Windows 8 Store Apps (3) - 控件之内容控件: ToolTip, Frame, AppBar, ContentControl, ContentPresenter ...

  8. C# windows服务:C#windows服务中的Timer控件的使用

    C# windows服务程序中的Timer控件的使用问题是如何解决的呢? 今天和同事一起研究了下C# windows服务程序中的Timer控件的使用的写法. 我们在建立一个C# windows服务程序 ...

  9. Visual Studio 2008 添加MScomm控件的方法

    1.下载MSCOMM.zip,解压后包含4个文件:MSCOMM32.OCX, MSCOMM.SRG, MSCOMM32.DEP, MSCOMM32.OCA 2.将Mscomm.srg, Mscomm3 ...

随机推荐

  1. Jmeter 4.0 对返回Json处理

    研究这个的目的是:如果返回信息是比较复杂的,需要对返回信息中数据以及数据的层级做断言 我找了一些我们的接口,层级关系都太简单了,最复杂的就是这两个了:[而且都是get接口,原来get接口还要增加测试点 ...

  2. [原]关于phycis集成到osgearth的(瞎写写)

    基于全球的物理系统集成技术 引言 随着····· 概述 基于osgEarth渲染引擎,引入先进的物理引擎physics. 本篇主要讲述:原理和解决思路. 原理要点: 空间坐标转换 物理引擎与渲染引擎同 ...

  3. Python -- Json 数据编码及解析

    Python  --  Json  数据编码及解析 Json 简单介绍 JSON: JavaScript Object Notation(JavaScript 对象表示法) JSON 是存储和交换文本 ...

  4. angular编译机制

    转载https://segmentfault.com/a/1190000011562077 Angular编译机制 前言 http://www.cnblogs.com/ztwBlog/p/620975 ...

  5. Redis之字符串类型命令

    String(字符串) string 是 redis 最基本的类型,你可以理解成与 Memcached 一模一样的类型,一个 key 对应一个 value. string 类型是二进制安全的.意思是 ...

  6. Appium 坑

    1. [Android]click没有反应 https://testerhome.com/topics/9610 在某些手机上有个安全选项,需要在开发者选项->安全设置(允许模拟点击),打开开关

  7. jsp session/application

    session的增加读取 session.setAttribute("username", "张三"); String u = (String) session ...

  8. git查看本地分支关联(跟踪)的远程分支之间的对应关系,本地分支对应哪个远程分支

    git branch -vv: [root@realserver git-test]# git branch -vv  bug    23043a7 add new.txt master.* dev  ...

  9. log4j配置文件位置详解

    自动加载配置文件: (1)如果采用log4j输出日志,要对log4j加载配置文件的过程有所了解.log4j启动时,默认会寻找source folder下的log4j.xml配置文件,若没有,会寻找lo ...

  10. DIV字体

    1.如何设定文字字体.颜色.大小 —— 使用font font-style设定斜体,比如font-style: italicfont-weight设定文字粗细,比如font-weight: bold; ...