【问题标题】:How to get my current Location with GeoPoint API in Windows Store Apps?如何在 Windows 应用商店应用程序中使用 GeoPoint API 获取我当前的位置?
【发布时间】:2019-03-26 05:57:22
【问题描述】:

我正在将 WP8 应用程序迁移到 W8.1,并且我一直在阅读 Geoposition API 不应该更多地用于 W8.1/WP8.1 或更新的操作系统(我在MSDN)。但是我找不到任何示例或想法如何使用 Geopoint API 获取我的当前位置。这是我当前的代码:

public async void GetSinglePositionAsync() {
    Geolocator geolocator = null;
    Geopoint geoposition = null;

    try
    {
        geolocator = new Windows.Devices.Geolocation.Geolocator();

        geolocator.DesiredAccuracy = PositionAccuracy.High;

        geoposition = await geolocator.GetGeopositionAsync();

        double latitude = geoposition.Position.Latitude;
        double longitude = geoposition.Position.Longitude;
        int altitude = (int)geoposition.Position.Altitude;

    }
    catch (Exception ex)
    {
        // Something else happened while acquiring the location.
        lblGravity.Text = ex.ToString();
    }
}

我最大的问题是当我初始化地理定位变量时,因为它给了我这个错误:“无法将类型 'Windows.Devices.Geolocation.Geoposition' 隐式转换为 'Windows.Devices.Geolocation.Geopoint'” em>,我不知道如何转换它或其他方法来初始化它。

非常感谢您宝贵的时间和帮助。提供的答案也可以在最新的 Windows 上实现。

【问题讨论】:

    标签: c# geolocation windows-store-apps windows-8.1


    【解决方案1】:

    这段代码可以翻译。

    public async void getposition() {
        Geolocator geolocator = new Geolocator();
        Geoposition geoposition = null;
        geoposition = await geolocator.GetGeopositionAsync();
        MyMap.Center = geoposition.Coordinate.Point;
        // zoom level
        MyMap.ZoomLevel = 15;
    }
    

    【讨论】:

      【解决方案2】:
      public async void GetSinglePositionAsync()
      {
          Geolocator myGeolocator = new Geolocator();
          Geoposition myGeoposition = await myGeolocator.GetGeopositionAsync();
          Geocoordinate myGeocoordinate = myGeoposition.Coordinate;
          GeoCoordinate myGeoCoordinate = CoordinateConverter.ConvertGeocoordinate(myGeocoordinate);
      }
      

      How to show your current location

      【讨论】:

      • 这个例子是针对 Geopoint API 的?因为您正在使用 Geoposition 并且您不应该再使用。这就是我要问的。谢谢。
      猜你喜欢
      • 1970-01-01
      • 2014-02-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-31
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多