Windows Phone 8获取本机位置
来源:互联网 发布:淘宝宝贝分类怎么设置 编辑:程序博客网 时间:2024/03/29 19:11
private Geolocator mMyGeolocator = null;// 这里给出完整的命名空间private System.Device.Location.Geocoordinate mMyGeoCoordinate = null;/// <summary> /// 定位到本机位置 /// </summary> private async void getMyLocation() { try { // Get my current location. if (mMyGeolocator == null) { mMyGeolocator = new Geolocator(); mMyGeolocator.DesiredAccuracy = PositionAccuracy.High; mMyGeolocator.MovementThreshold = 30; mMyGeolocator.DesiredAccuracyInMeters = 50; // 状态改变事件的委托函数 mMyGeolocator.StatusChanged += myGeolocator_StatusChanged; // 位置改变的委托函数 mMyGeolocator.PositionChanged += myGeolocator_PositionChanged; } // 获得原始数据,类型为Geoposition Geoposition myGeoposition = await mMyGeolocator.GetGeopositionAsync(maximumAge: TimeSpan.FromMinutes(2), timeout: TimeSpan.FromSeconds(10)); // 获得我的坐标的原始数据,注意这里得到的数据与mMyGeoCoordinate类型不同,所有需要转换 Windows.Devices.GeolocationGeocoordinate myGeocoordinateTemp = myGeoposition.Coordinate; // 转换后的真实经纬度 mMyGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinateTemp); } catch (Exception e) { DebugMsg.debug("getMyLocation 错误 : " + e.ToString()); } } /// <summary> /// 状态改变 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void myGeolocator_StatusChanged(Geolocator sender, StatusChangedEventArgs args) { switch (args.Status) { case PositionStatus.Disabled: MessageBox.Show("位置服务没有开启,请到[ 设置-位置 ]页面开启位置服务"); break; case PositionStatus.Initializing: DebugMsg.debug("位置服务初始化中..."); break; case PositionStatus.NoData: DebugMsg.debug("没有获取到位置数据,请重试..."); break; case PositionStatus.Ready: DebugMsg.debug("正在获取GPS数据..."); break; } } /// <summary> /// 位置改变后定位到该点,在更新我的位置。这样就会实现实时的位置显示 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> void myGeolocator_PositionChanged(Geolocator sender, PositionChangedEventArgs e) { // 获取到位置数据 Geocoordinate coordinateTemp = e.Position.Coordinate; // mMyGeoCoordinate与coordinateTemp的类型不同,需要转换一下 mMyGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(coordinateTemp); }
转换类的代码:
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Device.Location; // Provides the GeoCoordinate class.using Windows.Devices.Geolocation; //Provides the Geocoordinate class.namespace CommuteGreener.Utils{ 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 ); } }}
- Windows Phone 8获取本机位置
- Windows Phone 7 - 获取本机号码?
- Windows Phone 8获取设备ID
- windows phone 获取回车键
- Windows Phone 7回车键获取
- Windows Phone获取经纬度信息
- Windows Phone 获取手机信息
- 微软公布Windows Phone 8 SDK获取方式
- Windows Phone 8
- windows Phone 8 (1)
- windows Phone 8 (2)
- windows Phone 8 (3)
- windows Phone 8 (4)
- windows Phone 8 (5)
- windows Phone 8 (6)
- windows Phone 8 (7)
- Windows phone 8 推送
- Windows Phone 7 系统信息获取示例
- TPCH
- python基础知识
- 关于远程唤醒技术的相关资料
- html5学习笔记本地存储
- IOS APP提交流程
- Windows Phone 8获取本机位置
- 线程Thread总结1
- Android读写文件
- 软件质量管理的尴尬
- 搞不懂的问题
- html5学习笔记之离线缓存
- ucOS的移植
- Linq 操作DataTable
- DataGuard主备服务器网络暂时中断