2016-08-23 36 views
-1

你好,我在xamrian形成一個應用程序,需要從設備獲得的地理位置數據,然後把地理位置座標工作進入forecast.io網址我使用的由詹姆斯Montemagno的Geolocator插件,我使用的是閱讀我建議的代碼,但是我得到以下錯誤4次:「控制檯」的名稱並不在當前的背景下存在xamrian形式應用

The name 'Console' does not exist in the current context 

這裏是我的代碼:

using AppName.Data; 
using Xamarin.Forms; 
using Plugin.Geolocator; 

namespace AppName.Radar 
{  
    public partial class RadarHome : ContentPage 
    { 
     public RadarHome() 
     {  
      var locator = CrossGeolocator.Current; 
      locator.DesiredAccuracy = 50; 

      var position = await locator.GetPositionAsync(timeout: 10000); 

      Console.WriteLine("Position Status: {0}", position.Timestamp); 
      Console.WriteLine("Position Latitude: {0}", position.Latitude); 
      Console.WriteLine("Position Longitude: {0}", position.Longitude); 
      var LatLong = position.Latitude + "," + position.Longitude; 

      var browser = new WebView(); 
      browser.Source = "https://forecast.io/?mobile=1#/f/" + LatLong; 

      Content = browser; 
     } 
    } 
} 

我正在使用Visual Studio Update 3對我做錯了什麼想法?

感謝提前:)

+4

那麼除了別的,如果你想使用'System.Console',你缺少一個'使用系統;'指令。但我不知道'System.Console'是否對於Xamarin Forms甚至是存在的...... –

+3

您應該使用'Debug.WriteLine'來代替,因爲'System.Console'在PCL中不存在。類似於這個答案:http://stackoverflow.com/a/9675897/1048571/ http://brianlagunas.com/write-platform-specific-code-with-a-portable-class-library-pcl/ –

回答

22

因爲你的代碼與特定的配置文件的System.Console不可用了PCL。

使用Debug.WriteLine("Text here")操作,不要忘了添加using System.Diagnostics;

+0

它應該需要注意的是,由於它們沒有附帶'System.Console',而是'Debug.WriteLine',所以它們使用的是PCL配置文件的限制。 'ContentPage'只是Xamarin中的一個類.Forms –

+0

@JonDouglas Debug.WriteLine如何替代Console.WriteLine?他們是獨立的。 –

+0

@JonDouglas更新了答案,但爲了解決問題,我只是保持簡單。但感謝提醒。 – jzeferino

相關問題