我是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