2016-11-22 14 views
0

私はUWPアプリを書いています。PCLのUWPアプリの位置定義を作成

私はUWPプロジェクト用にPCLを作成しました。

緯度と経度のデータをダウンロードします(天気予報アプリ)。また、私はスマートフォンの場所のために緯度と経度を定義する必要があります。ここで

は私のコードです:この行Geoposition pos = await geoLocator.GetGeopositionAsync();

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; 
    } 

私はエラーがあります: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'.

私はこの問題を解決するにはどうすればよいですか?

ありがとうございました。

答えて

1

ポータブルクラスライブラリの目的は、クロスプラットフォームのアプリケーションとライブラリを構築し、アプリケーションのさまざまな部分でコードを共有できるようにすることです。

VS 2015でPCLを作成する場合は、Windows 10、汎用アプリのAPIの種類を指定できます。しかし、ここでは、この方法は従来のWin32アプリケーションではなく、WinRTアプリケーションでのみ使用できます。これをPCLに入れるのは良い設計ではないと思います。これらのコードをUWPアプリケーションに移動できます。

それともあなたは自分のUWPのアプリのためのライブラリを作成したい場合は、あなたの代わりにClass Library (Portable)を作成するClass Library (Universal Windows)を作成することができます。

enter image description here

あなたはこれら二つの異なるのPCLのReferencesを比較することができます。

クラスライブラリ(ポータブル):

enter image description here

クラスライブラリ(ユニバーサルWindowsの場合):画像内

enter image description here

参照は、上記のあなたのクラスのUWPのAPIの使用を可能にしますとしょうかん。

関連する問題