我是C#的初学者,但我已经使用了很多Java。我正尝试在我的应用程序中使用以下代码来获取位置数据。我想提出一个Windows 8桌面应用程序来使用我的设备的GPS传感器:在Windows 8桌面应用中获取位置
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Devices.Sensors;
using Windows.Devices.Geolocation;
using Windows.Devices.Geolocation.Geoposition;
using Windows.Foundation;
namespace Hello_Location
{
public partial class Form1 :
{
public Form1()
{
InitializeComponent();
}
async private void Form1_Load(object sender, EventArgs e)
{
Geolocator loc = new Geolocator();
try
{
loc.DesiredAccuracy = PositionAccuracy.High;
Geoposition pos = await loc.GetGeopositionAsync();
var lat = pos.Coordinate.Latitude;
var lang = pos.Coordinate.Longitude;
Console.WriteLine(lat+ " " +lang);
}
catch (System.UnauthorizedAccessException)
{
// handle error
}
}
private void button1_Click(object sender, EventArgs e)
{
}
}
}
我得到这个错误:
'await' requires that the type 'Windows.Foundation.IAsyncOperation' have a suitable GetAwaiter method. Are you missing a using directive for 'System'? C:\Users\clidy\documents\visual studio 2012\Projects\Hello-Location\Hello-Location\Form1.cs
我该如何解决这个问题?
如果您可以指向我一些C#位置资源和Windows desktop应用程序的传感器API,那么它将非常有用。在Google上搜索时,我只能获得Windows RT API。
您引用的类型仅适用于Windows应用商店应用。您可能能够关注[这些](http://www.wintellect.com/CS/blogs/jeffreyr/archive/2011/09/20/using-the-windows-runtime-from-a-non-metro- application.aspx)手动添加引用和构建的说明,但我没有经验。 –
实际上[这篇文章](http://software.intel.com/en-us/articles/geo-location-on-windows-8-desktop-applications-using-winrt)声称它非常简单。我还没有测试过。我将在未来两周内做更多的研究。 – Bart