我正在编写UWP应用程序。为PCL制作UWP应用程序的位置定义
我为UWP项目创建了PCL。
它下载纬度和经度的数据(这是天气应用程序)。此外,我需要为智能手机的位置定义纬度和经度。
这里是我的代码:
public class OpenWeatherViewModel
{
private const string APPID = "f3c45b5a19426de9ea6ba7eb6c6969d7";
private List<RootObject> weatherList;
public List<RootObject> WeatherListList
{
get { return weatherList; }
set { weatherList = value; }
}
public OpenWeatherViewModel()
{
Data_download();
}
public async void Data_download()
{
var geoLocator = new Geolocator();
geoLocator.DesiredAccuracy = PositionAccuracy.High;
Geoposition pos = await geoLocator.GetGeopositionAsync();
string latitude = "Latitude: " + pos.Coordinate.Point.Position.Latitude.ToString();
string longitude = "Longitude: " + pos.Coordinate.Point.Position.Longitude.ToString();
var url = String.Format(
"http://api.openweathermap.org/data/2.5/weather?lat={0}&lon={1}&units=metric&APPID=" + APPID, latitude, longitude);
var json = await FetchAsync(url);
List<RootObject> rootObjectData = JsonConvert.DeserializeObject<List<RootObject>>(json);
WeatherListList = new List<RootObject>(rootObjectData);
}
public async Task<string> FetchAsync(string url)
{
string jsonString;
using (var httpClient = new System.Net.Http.HttpClient())
{
var stream = await httpClient.GetStreamAsync(url);
StreamReader reader = new StreamReader(stream);
jsonString = reader.ReadToEnd();
}
return jsonString;
}
该行Geoposition pos = await geoLocator.GetGeopositionAsync();
我有错误:Error CS0012 The type 'IAsyncOperation<>' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.FoundationContract, Version=2.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime'.
我怎样才能解决这个问题?
感谢您的帮助。