【发布时间】:2014-03-04 10:47:19
【问题描述】:
我尝试使用 C# 中的 Windows 运行时从桌面应用程序获取我的 GPS 位置。
我跟随this how-to 设置Visual Studio 和this code sample 创建以下琐碎代码作为C# 控制台应用程序:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.IO;
using System.Runtime;
using System.Windows;
using Windows;
using Windows.Devices.Geolocation;
using Windows.Foundation;
using Windows.Foundation.Collections;
namespace GeoLocCS
{
public sealed partial class Program
{
static void Main(string[] args)
{
Test test = new Test();
Console.Read();
}
}
public class Test
{
private Geolocator geolocator;
public Test()
{
Console.WriteLine("test");
geolocator = new Geolocator();
this.getPos();
}
async void getPos()
{
Geoposition pos = await geolocator.GetGeopositionAsync();
Console.WriteLine(pos.Coordinate.Latitude.ToString());
}
}
}
尝试编译时,出现错误:
Error 1 'await' requires that the type 'Windows.Foundation.IAsyncOperation<Windows.Devices.Geolocation.Geoposition>' have a suitable GetAwaiter method. Are you missing a using directive for 'System'?
我尝试引用每个可以引用的 DLL,例如“System.runtime”、“System.Runtime.WindowsRuntime”、“Windows.Foundation”...
我错过了什么?
谢谢你的回答,
谢尔盖
【问题讨论】:
-
听起来像重复,我想stackoverflow.com/questions/13125793/… 可能会给你一个解决方案
-
@RemcoBrilstra 我也希望它会,但没有。我尝试引用
System.Runtime.WindowsRuntime.dll,但仍然收到错误。
标签: c# geolocation windows-runtime async-await