在Windows Phone 7上获取GPS坐标
如何获得Windows Phone 7上当前的GPS坐标?
这是一个简单的例子:
GeoCoordinateWatcher watcher; watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.Default) { MovementThreshold = 20 }; watcher.PositionChanged += this.watcher_PositionChanged; watcher.StatusChanged += this.watcher_StatusChanged; watcher.Start(); private void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e) { switch (e.Status) { case GeoPositionStatus.Disabled: // location is unsupported on this device break; case GeoPositionStatus.NoData: // data unavailable break; } } private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e) { var epl = e.Position.Location; // Access the position information thusly: epl.Latitude.ToString("0.000"); epl.Longitude.ToString("0.000"); epl.Altitude.ToString(); epl.HorizontalAccuracy.ToString(); epl.VerticalAccuracy.ToString(); epl.Course.ToString(); epl.Speed.ToString(); e.Position.Timestamp.LocalDateTime.ToString(); }
GeoCoordinateWatcher是提供此function的类。 有一个如何 ,MSDN上的示例和一些其他资源 。