window phone 获取经纬度信息
webphp
13年前
<p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" class="selflink">GeoCoordinateWatcher</span></span> 类提供基于坐标的位置数据,其来自当前的位置提供程序。 来自当前位置提供程序的基于坐标的位置数据,该提供程序是计算机上优先级别最高的位置提供程序,其优先级别取决于一系列因素,如:来自所有提供程序的数据的存在时间和准确性、位置应用程序请求的准确性、与位置提供程序关联的电量消耗和性能影响。 当前位置提供程序可能会随时间改变,例如,当 GPS 设备失去内部附属信号功能并且 Wi-Fi 三边转换法提供程序成为计算机上最准确的提供程序时。</p> <p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;">若要开始访问位置数据,请创建 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" class="selflink">GeoCoordinateWatcher</span></span>,然后调用 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796095061150">Start</a></span> 或 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796187095105">TryStart</a></span>,开始从当前的位置提供程序获取数据。</p> <p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;">可检查 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796261981573">Status</a></span> 属性来确定数据是否可用。 如果数据可用,您可以从 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796339793098">Position</a></span> 属性一次获取位置,或通过处理 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796414162980">PositionChanged</a></span> 事件接收连续的位置更新。</p> <p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796489610934">Permission</a></span>、<span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796261981573">Status</a></span> 以及 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796339793098">Position</a></span> 属性支持 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796594090031">INotifyPropertyChanged</a></span>,因此应用程序可以数据绑定到这些属性。</p> <p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;">在 Windows 7 中,如果位置提供程序已经安装并能够解析计算机的位置,则所有 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796681096110">System.Device.Location</a></span> 类都完全正常。</p> <div style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;" class="alert"> <table class="ke-zeroborder"> <tbody style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <tr style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <th style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><strong>注意</strong></th> </tr> <tr style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <td style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <p style="padding-bottom:0px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:inherit;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;">在 Windows 7 Starter 版上,唯一受支持的位置提供商是控制面板中的默认位置提供程序,且必须安装外接程序以指定纬度和经度。</p> </td> </tr> </tbody> </table> </div> <p style="padding-bottom:0px;line-height:16px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;" class="label">注意</span>:在 Windows 7 之前的 Windows 版本中,以下条件适用:</p> <ul style="padding-bottom:0px;line-height:19px;border-right-width:0px;margin:12px 0px 12px 12px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:'Segoe UI','Lucida Grande',Verdana,Arial,Helvetica,sans-serif;border-top-width:0px;border-bottom-width:0px;color:#333333;font-size:13px;border-left-width:0px;padding-top:0px;"> <li style="padding-bottom:0px;border-right-width:0px;background-color:transparent;list-style-type:none;margin:0px;padding-left:12px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <p style="padding-bottom:0px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:inherit;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;">可创建具有构造函数的所有 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796681096110">System.Device.Location</a></span> 对象,但 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796261981573">Status</a></span> 属性将始终具有值 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796781766782">Disabled</a></span>。</p> </li> <li style="padding-bottom:0px;border-right-width:0px;background-color:transparent;list-style-type:none;margin:0px;padding-left:12px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <p style="padding-bottom:0px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:inherit;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796339793098">Position</a></span> 的 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796874196663">Location</a></span> 属性所指示的位置将始终为 <span style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"><a style="padding-bottom:0px;border-right-width:0px;margin:0px;padding-left:0px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;color:#0066dd;border-left-width:0px;text-decoration:none;padding-top:0px;" href="/misc/goto?guid=4959500796946179008">Unknown</a></span>。</p> </li> <li style="padding-bottom:0px;border-right-width:0px;background-color:transparent;list-style-type:none;margin:0px;padding-left:12px;outline-width:0px;padding-right:0px;font-family:inherit;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;"> <p style="padding-bottom:0px;border-right-width:0px;margin-top:0px;outline-width:0px;font-family:inherit;margin-bottom:12px;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;padding-top:0px;">不会引发位置事件。</p><pre class="brush:c#; toolbar: true; auto-links: false;">using System; using System.Device.Location; namespace GetLocationEvent { class Program { static void Main(string[] args) { CLocation myLocation = new CLocation(); myLocation.GetLocationEvent(); Console.WriteLine("Enter any key to quit."); Console.ReadLine(); } class CLocation { GeoCoordinateWatcher watcher; public void GetLocationEvent() { this.watcher = new GeoCoordinateWatcher(); this.watcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged); bool started = this.watcher.TryStart(false, TimeSpan.FromMilliseconds(2000)); if (!started) { Console.WriteLine("GeoCoordinateWatcher timed out on start."); } } void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { PrintPosition(e.Position.Location.Latitude, e.Position.Location.Longitude); } void PrintPosition(double Latitude, double Longitude) { Console.WriteLine("Latitude: {0}, Longitude {1}", Latitude, Longitude); } } } }</pre> <p></p> </li> </ul>