1

チュートリアルの GPS を試したところ、次のエラー メッセージが表示されました。何が問題だと思われますか?

http://docs.xamarin.com/recipes/android/os_device_resources/gps/get_current_device_location

システムを使用する;
Android.App の使用;
Android.Content の使用;
Android.Runtime の使用;
Android.Views の使用;
Android.Widget の使用;
Android.OS の使用;

//-- これらを追加


Android.Locations の使用;
System.Collections.Generic の使用;
System.Threading の使用;
System.Text を使用します。


名前空間 GetLocation
{

    [Activity(Label = "Get Location", MainLauncher = true, Icon = "@drawable/icon")]
    パブリック クラス Activity1 : アクティビティ、ILocationListener
    {
        //int カウント = 1;
        プライベート ロケーション _currentLocation;
        プライベート LocationManager _locationManager;
        プライベート TextView _locationText;
        プライベート TextView _addressText;

        protected override void OnCreate (バンドル バンドル)
        {
            base.OnCreate (バンドル);
            SetContentView(Resource.Layout.Main);
            _addressText = FindViewById(Resource.Id.address_text);
            _locationText = FindViewById(Resource.Id.location_text);
            FindViewById(Resource.Id.get_address_button).Click += AddressButton_OnClick;

            InitializeLocationManager();        
        }

        //public void OnLocationChanged(Location location) {}
        public void OnProviderDisabled(文字列プロバイダー) {}
        public void OnProviderEnabled(文字列プロバイダー) {}
        public void OnStatusChanged(string provider, Availability status, Bundle extras) {}

        private void InitializeLocationManager()
        {
            _locationManager = (ロケーションマネージャー) GetSystemService(ロケーションサービス);
            var criteriaForLocationService = 新しい基準
            {
                Accuracy = Accuracy.Fine
            };
            var AcceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

            if (acceptableLocationProviders.Any())
            {
                _locationProvider =acceptableLocationProviders.First();
            }
            そうしないと
            {
                _locationProvider = 文字列.空;
            }
        }

        保護されたオーバーライド void OnResume()
        {
            base.OnResume();
            _locationManager.RequestLocationUpdates(_locationProvider, 0, 0, これ);
        }

        保護されたオーバーライド void OnPause()
        {
            base.OnPause();
            _locationManager.RemoveUpdates(これ);
        }

        private void AddressButton_OnClick(オブジェクト送信者、EventArgs eventArgs)
        {
            if (_currentLocation == null)
            {
                _addressText.Text = "現在の場所を特定できません。";
                戻る;
            }
            新しいスレッド(() =>
                       {
                var addressText = "場所が見つかりません。";
                var geocoder = new Geocoder(this);
                var addressList = geocoder.GetFromLocation(_currentLocation.Latitude, _currentLocation.Longitude, 50);
                var address = addressList.FirstOrDefault();

                if (アドレス != null)
                {
                    var deviceLocation = new StringBuilder();
                    for (var i = 0; i { _addressText.Text = addressText; });
            })。始める();
        }

        public void OnLocationChanged(場所の場所)
        {
            _currentLocation = 場所;
            if (_currentLocation == null)
            {
                _locationText.Text = "現在地を特定できません。";
            }
            そうしないと
            {
                _locationText.Text = String.Format("{0},{1}", _currentLocation.Latitude, _currentLocation.Longitude);
            }
        }
    }
}

これらの問題を解決する方法:

エラーメッセージ

1)

エラー CS1061: 'System.Collections.Generic.IList' には 'Any' の定義が含まれておらず、タイプ 'System.Collections.Generic.IList' の最初の引数を受け入れる拡張メソッド 'Any' が見つかりませんでした (見つからない場合using ディレクティブまたはアセンブリ参照?) (CS1061) (GetLocation)

2)Error CS0103: The name '_locationProvider' does not exist in the current context (CS0103) (GetLocation)

3)Error CS1061: 'System.Collections.Generic.IList<string>' does not contain a definition for 'First' and no extension method 'First' accepting a first argument of type 'System.Collections.Generic.IList<string>' could be found (are you missing a using directive or an assembly reference?) (CS1061) (GetLocation)

4)Error CS0103: The name '_locationProvider' does not exist in the current context (CS0103) (GetLocation)

5)Error CS1061: 'System.Collections.Generic.IList<Android.Locations.Address>' does not contain a definition for 'FirstOrDefault' and no extension method 'FirstOrDefault' accepting a first argument of type 'System.Collections.Generic.IList<Android.Locations.Address>' could be found (are you missing a using directive or an assembly reference?) (CS1061) (GetLocation)

6) ファイル名が MainActivity.cs で、Activity クラスが呼び出されているかどうかは重要ですか:

public class Activity1 : Activity, ILocationListener
{
}

ありがとう

4

1 に答える 1