Getting GPS coordinates on Windows phone 7

前端 未结 2 1145
半阙折子戏
半阙折子戏 2020-12-03 01:10

How can I get the current GPS coordinates on Windows Phone 7?

相关标签:
2条回答
  • 2020-12-03 01:24

    GeoCoordinateWatcher is the class that provides this functionality. There is a How To, a sample and some other resources on MSDN.

    0 讨论(0)
  • 2020-12-03 01:26

    Here's a simple example:

    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();
    }
    
    0 讨论(0)
提交回复
热议问题