2016-08-23 53 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

相关问题