摘要:

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. Java中带标签的break,continue

    首先不带标签的break,continue 就不介绍了.大家平时用的最多的也就是这样的情况了. 首先Java中没有goto,但是可以利用带标签的break, continue来实现类似的跳转. 首先来 ...

  2. LIBS+=

    ZC: “LIBS+=”是要结合“LIBPATH += ”一起使用的?类似下面的用法: ZC: “LIBS+=”指明lib文件的名称,“LIBPATH += ”指明lib文件的路径.最后还要把DLL文 ...

  3. 理解Fragment的生命周期

    与活动类似,Fragment也有自己的生命周期.理解Fragment的生命周期有助于在Fragment销毁时能恰当地保存其实例,然后在重新创建时能够将其恢复至之前的状态. 下面的“试一试”将研究Fra ...

  4. C#复制文件

    string pLocalFilePath ="";//要复制的文件路径 string pSaveFilePath ="";//指定存储的路径 if (File ...

  5. Ubuntu 的 desktop 和 server 还是有区别。

    除了安装的包,比如 GUI, LAMP 上有差别之外,所用的内核也稍有不一样. 不过desktop可以通过安装 sudo apt-get install linux-image-server 之后,编 ...

  6. JQuery.Ajax()的data参数传递方式

    最近,新学c# mvc,通过ajax post方式传递数据到controller.刚开始传递参数,controller中总是为null.现记录一下,可能不全,纯粹记个学习日记. 重点在于参数的方式,代 ...

  7. python-day8-列表的内置方法

    # l=[1,2,3] #l=list([1,2,3])# print(type(l)) #pat1===>优先掌握部分# 索引## 切片l=['a','b','c','d','e','f'] ...

  8. 生成图片验证码(.NET)

    一.生成随机字符串 方法一: public string CreateRandomCode(int codeCount) { string allChar = "0,1,2,3,4,5,6, ...

  9. OAF多语言的实现

    在之前的文章中转载了一篇关于多语言实现的文章. OAF中多语言的实现(转) 现在我来讲讲另外一种情况. 在建立工程项目没有特别选择语言,所以所有的PG或RN页面都是英文的,在页面原文件中可看到如下内容 ...

  10. OC Xcode中常见的错误

    在开发的过程中难免会遇到很多的错误,可是当看到系统给出的英文时,又不知道是什么意思.所以这篇文章总结了Xcode中常见的一些英文单词及词组,可以帮助初学的人快速了解给出的提示.多练习,就肯定能基本掌握 ...