当前位置: 首页>>代码示例>>C#>>正文


C# LocationManager.GetLastKnownLocation方法代码示例

本文整理汇总了C#中Android.Locations.LocationManager.GetLastKnownLocation方法的典型用法代码示例。如果您正苦于以下问题:C# LocationManager.GetLastKnownLocation方法的具体用法?C# LocationManager.GetLastKnownLocation怎么用?C# LocationManager.GetLastKnownLocation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Android.Locations.LocationManager的用法示例。


在下文中一共展示了LocationManager.GetLastKnownLocation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: GetLocation

		public Location GetLocation() {
			try {
				locationManager = (LocationManager)mContext.GetSystemService("location");

				// Getting GPS status
				isGPSEnabled = locationManager.IsProviderEnabled(LocationManager.GpsProvider);

				// Getting network status
				isNetworkEnabled = locationManager.IsProviderEnabled(LocationManager.NetworkProvider);

				if (!isGPSEnabled && !isNetworkEnabled) {
					//showalert in activity
				}
				else {
					this.CanGetLocation = true;
					if (isNetworkEnabled) {
						locationManager.RequestLocationUpdates(
								LocationManager.NetworkProvider,
								MIN_TIME_BW_UPDATES,
								MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
						if (locationManager != null) {
							location = locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);
							if (location != null) {
								latitude = location.Latitude;
								longitude = location.Longitude;
							}
						}
					}
					if (isGPSEnabled) {
						if (location == null) {
							locationManager.RequestLocationUpdates(
									LocationManager.GpsProvider,
									MIN_TIME_BW_UPDATES,
									MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
							if (locationManager != null) {
								location = locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
								if (location != null) {
									latitude = location.Latitude;
									longitude = location.Longitude;
								}
							}
						}
					}
				}
			} catch (Exception e) {
				AlertsService.ShowToast(this.mContext, "Nie masz w³¹czonej lokalizacji!");
			}

			return location;
		}
开发者ID:MarcinSzyszka,项目名称:MobileSecondHand,代码行数:50,代码来源:GpsLocationService.cs

示例2: start

        public void start()
        {
            if (_tracking) return;

            var ls = (LocationManager) _context.GetSystemService(Context.LocationService);
            //var aproviders = ls.AllProviders.ToArray();
            //var hasGPS = ls.IsProviderEnabled(LocationManager.GpsProvider);
            //var hasNET = ls.IsProviderEnabled(LocationManager.NetworkProvider);

            //if (!hasGPS || !hasNET)
            {
                //throw new Exception("Must have both GPS and Net location providers");
            }

            _locationManager = ls;

            var lastLocation = _locationManager.GetLastKnownLocation(LocationManager.PassiveProvider);
            Location = createGeoLocation(lastLocation);

            var criteria = new Criteria();
            criteria.Accuracy = Accuracy.Fine;
            criteria.AltitudeRequired = true;

            var providers = _locationManager.GetProviders(criteria, true).ToArray();
            foreach (var provider in providers)
            {
                _locationManager.RequestLocationUpdates(provider, 1000, 5, _listener, Looper.MainLooper);
            }

            _tracking = true;
        }
开发者ID:42Spikes,项目名称:F2S,代码行数:31,代码来源:LocationManagerFacade.cs

示例3: StartService

        public void StartService()
        {
            _locMan = Application.Context.GetSystemService (Context.LocationService) as LocationManager;

            if (_locMan.GetProvider (LocationManager.GpsProvider) != null && _locMan.IsProviderEnabled (LocationManager.GpsProvider))
            {
                _pi = PendingIntent.GetBroadcast(Application.Context, 0, new Intent(), PendingIntentFlags.UpdateCurrent);
                _locMan.RequestLocationUpdates(LocationManager.GpsProvider, 2000, 5, _pi);
                _locMan.GetLastKnownLocation (LocationManager.GpsProvider);
            }

            else
                throw new GPSNotEnabledException (Const.NO_GPS_ERROR_MESSAGE);
        }
开发者ID:giuunit,项目名称:toronto-party-advisor-xamarin,代码行数:14,代码来源:LocationService.cs

示例4: LocListener

		public LocListener(LocationManager lm, SensorManager sm) : base()
		{
			// Get LocationManager
			locManager = lm;

			var locationCriteria = new Criteria ()
			{
				Accuracy = global::Android.Locations.Accuracy.Fine,
				AltitudeRequired = true,
				PowerRequirement = Power.Low
			};

			locationProvider = locManager.GetBestProvider(locationCriteria, true);

			if (locationProvider == null)
				throw new Exception("No location provider found");

			List<String> providers = locManager.GetProviders(true) as List<String>;

			// Loop over the array backwards, and if you get an accurate location, then break out the loop
			Location loc = null;

			if (providers != null) {
				for (int i = providers.Count - 1; i >= 0; i--) {
					loc = locManager.GetLastKnownLocation(providers[i]);
					if (loc != null) 
						break;
				}
			}

			if (loc != null)
			{
				lat = loc.Latitude;
				lon = loc.Longitude;
				alt = loc.Altitude;
				accuracy = loc.Accuracy;
			}

			sensorManager = sm;
			accelerometer = sensorManager.GetDefaultSensor(SensorType.Accelerometer);
			magnetometer = sensorManager.GetDefaultSensor(SensorType.MagneticField);
		}
开发者ID:jonny65,项目名称:WF.Player.Android,代码行数:42,代码来源:LocListener.cs

示例5: InitializeLocationManager

		void InitializeLocationManager()
		{
			_locationManager = (LocationManager) GetSystemService(LocationService);

			Criteria criteriaForLocationService = new Criteria
			{
				Accuracy = Accuracy.Fine
			};
			IList<string> acceptableLocationProviders = _locationManager.GetProviders(criteriaForLocationService, true);

			if (acceptableLocationProviders.Any())
			{
				_locationProvider = acceptableLocationProviders.First();

				this.OnLocationChanged (_locationManager.GetLastKnownLocation (_locationProvider));
			}
			else
			{
				_locationProvider = string.Empty;
			}
			Log.Debug(TAG, "Using " + _locationProvider + ".");
		}
开发者ID:hdknr,项目名称:WalkAround,代码行数:22,代码来源:MainActivity.cs

示例6: OnCreate

        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            SetContentView(Resource.Layout.location_demo);

            _builder = new StringBuilder();
            _geocoder = new Geocoder(this);
            _locationText = FindViewById<TextView>(Resource.Id.location_text);
            _locationManager = (LocationManager)GetSystemService(LocationService);

            var criteria = new Criteria() { Accuracy = Accuracy.NoRequirement };
            string bestProvider = _locationManager.GetBestProvider(criteria, true);

            Location lastKnownLocation = _locationManager.GetLastKnownLocation(bestProvider);

            if (lastKnownLocation != null)
            {
                _locationText.Text = string.Format("Last known location, lat: {0}, long: {1}",
                                                   lastKnownLocation.Latitude, lastKnownLocation.Longitude);
            }

            _locationManager.RequestLocationUpdates(bestProvider, 5000, 2, this);
        }
开发者ID:jorik041,项目名称:Sample-Projects,代码行数:24,代码来源:LocationActivity.cs

示例7: OnCreate

        protected override void OnCreate(Bundle bundle)
        {
            player = MediaPlayer.Create (this,Resource.Raw.police_alarm);
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            //_addressText = FindViewById<TextView>(Resource.Id.textView3);
            _latitudeText = FindViewById<TextView>(Resource.Id.txtLatitude);
            _longitudeText = FindViewById<TextView> (Resource.Id.txtLongitude);
            _locationManager = (LocationManager)GetSystemService(LocationService);

            var criteriaForLocationService = new Criteria
            {
                Accuracy = Accuracy.Medium
            };
            var acceptableLocationProviders = _locationManager.GetProviders (criteriaForLocationService, false);
            Location l=_locationManager.GetLastKnownLocation(acceptableLocationProviders.First());

            if (l == null) {
                _latitudeText.Text = 17.4417641.ToString();
                _longitudeText.Text = 78.3807515.ToString();
            } else {
                _latitudeText.Text = l.Latitude.ToString();
                _longitudeText.Text = l.Longitude.ToString();
            }

            //			FindViewById<TextView>(Resource.Id.address_button).Click += AddressButton_OnClick;
            //			_addressText = FindViewById<TextView> (Resource.Id.address_button);
            //			Address ();
            //FindViewById<TextView>(Resource.Id.add).Click += AddressButton_OnClick;
            //_timeText = FindViewById<TextView> (Resource.Id.txtSpeed);
            FindViewById<TextView>(Resource.Id.button1).Click += CallPolice_OnClick;
            FindViewById<TextView> (Resource.Id.button2).Click += alarm_click;
            FindViewById<TextView> (Resource.Id.showPopup).Click += contact;

            //				var sendsos = FindViewById<Button> (Resource.Id.button3);
            //			sendsos.Click += (sender, e) => {
            //				if(_latitudeText.Text=="" && _longitudeText.Text=="")
            //				{
            //					Toast.MakeText(this,"Gps is looking for your latitude and longitude positions kindly hold on",ToastLength.Short).Show();
            //				}
            //				else{
            //				SmsManager.Default.SendTextMessage("1234567890", null,"http://maps.google.com/maps?q="+_currentLocation.Latitude+","+_currentLocation.Longitude, null, null);
            //				}
            //				//SmsManager.Default.SendTextMessage(
            //			};

            //	FindViewById<TextView> (Resource.Id.button4).Click += cell_loc;

            var sendsosIntent = FindViewById<Button> (Resource.Id.button3);

            sendsosIntent.Click += (sender, e) => {
            //				double lat=_currentLocation.Latitude;
            //				double lon=_currentLocation.Longitude;
                PopupMenu menu=new PopupMenu(this,sendsosIntent);
                menu.Inflate(Resource.Menu.Main);
                menu.MenuItemClick += (s1, arg1) => {
                    //Console.WriteLine ("{0} selected", arg1.Item.TitleFormatted);
                    //ISharedPreferences sh=GetSharedPreferences("Contacts",
                    ISharedPreferences p = GetSharedPreferences ("Contacts", FileCreationMode.WorldReadable);
            //						var name = cursor2.GetString (cursor2.GetColumnIndex (ContactsContract.ContactsColumns.DisplayName));
            //						var number = cursor2.GetString (cursor2.GetColumnIndex (ContactsContract.CommonDataKinds.Phone.Number));
                    // 	ISharedPreferencesEditor e1 = p.Edit ();
            //						e.PutString (name, number);
            //						e.Commit ();
                    String val=p.GetString("name_contact","");
                    //	String val = p.GetString ("name", "");
                        Toast.MakeText (this, val, ToastLength.Short).Show();
                };

                // Android 4 now has the DismissEvent
                menu.DismissEvent += (s2, arg2) => {
                    Console.WriteLine ("menu dismissed");
                };

                menu.Show ();
                if(_latitudeText.Text=="")
                {
                    Toast.MakeText(this,"Gps is looking for your latitude and longitude positions kindly hold on",ToastLength.Short).Show();
                }
                else {
                    _locationManager = (LocationManager)GetSystemService(LocationService);

                    var criteriaForLocationService1 = new Criteria
                    {
                        Accuracy = Accuracy.Medium
                    };
                    var acceptableLocationProviders1 = _locationManager.GetProviders (criteriaForLocationService1, false);
                    Location l1=_locationManager.GetLastKnownLocation(acceptableLocationProviders1.First());

                    string lo="http://maps.google.com/maps?q="+l1.Latitude+","+l1.Longitude+"&mode=driving";
                    //string locationString = @"http://maps.google.com/maps/api/staticmap?center=" + _currentLocation.Latitude + "," + _currentLocation.Longitude;
                    //var i=new Intent(Intent.ActionView,Android.Net.Uri.Parse(lo));
                    //var intent=new Intent(Intent.ActionView,Android.Net.Uri.Parse("http://maps.google.com/maps?q=loc:56.3245,-3.24567"));

                //StartActivity(i);

            //				var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
            //				var smsIntent = new Intent (Intent.ActionSendto, smsUri);
            //					smsIntent.PutExtra("address","jelly");
//.........这里部分代码省略.........
开发者ID:sonalpathak,项目名称:MySecurity,代码行数:101,代码来源:MainActivity.cs

示例8: InitLocation

        private void InitLocation()
        {
            try
            {
                _locationManager = (LocationManager)_context.GetSystemService(LocationService);

                // getting GPS status
                _isGPSEnabled = _locationManager.IsProviderEnabled(LocationManager.GpsProvider);

                // getting network status
                _isNetworkEnabled = _locationManager.IsProviderEnabled(LocationManager.NetworkProvider);

                if (!_isGPSEnabled && !_isNetworkEnabled)
                {
                    // no network provider is enabled
                }
                else
                {
                    this._canGetLocation = true;
                    if (_isNetworkEnabled)
                    {
                        _locationManager.RequestLocationUpdates(LocationManager.NetworkProvider,
                            MIN_TIME_BW_UPDATES,
                            MIN_DISTANCE_CHANGE_FOR_UPDATES,
                            this);

                        Log.Debug("Network", "Network Enabled");

                        if (_locationManager != null)
                        {
                            _location = _locationManager.GetLastKnownLocation(LocationManager.NetworkProvider);

                            if (_location != null)
                            {
                                _latitude = _location.Latitude;
                                _longitude = _location.Longitude;
                            }
                        }
                    }

                    // if GPS Enabled get lat/long using GPS Services
                    if (_isGPSEnabled)
                    {
                        if (_location == null)
                        {
                            _locationManager.RequestLocationUpdates(
                                    LocationManager.GpsProvider,
                                    MIN_TIME_BW_UPDATES,
                                    MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
                            Log.Debug("GPS", "GPS Enabled");

                            if (_locationManager != null)
                            {
                                _location = _locationManager.GetLastKnownLocation(LocationManager.GpsProvider);
                                if (_location != null)
                                {
                                    _latitude = _location.Latitude;
                                    _longitude = _location.Longitude;
                                }
                            }
                        }
                    }
                }

            }
            catch (Exception e)
            {
                Log.Error("Location Error", e.StackTrace);
            }
        }
开发者ID:America4Animals,项目名称:AFA,代码行数:70,代码来源:GPSTracker.cs

示例9: OnResume

		//ON RESUME
		protected override void OnResume ()
		{
			base.OnResume (); 
			Log.Debug (tag, "OnResume called");

			// initialize location manager
			locMgr = GetSystemService (Context.LocationService) as LocationManager;

				var locationCriteria = new Criteria();

				locationCriteria.Accuracy = Accuracy.Coarse;
				locationCriteria.PowerRequirement = Power.Medium;

				string locationProvider = locMgr.GetBestProvider(locationCriteria, true);
				string prov=locationProvider.ToString();

				if(prov=="passive"){
					Log.Debug(tag, "Están deshabilitados los proveedores de ubicación: " + locationProvider.ToString());
					Toast.MakeText (this, "The Network Provider does not exist or is not enabled!", ToastLength.Long).Show ();
				gpsclass.PutString ("latitud", "nogps");
				gpsclass.PutString ("longitud", "nogps");
				}else{
					Log.Debug(tag, "Starting location updates with " + locationProvider.ToString());
					locMgr.RequestLocationUpdates (locationProvider, 2000, 0, this);
				}

			//Last Known Location
			Log.Debug(tag, "Se obtiene la ultima localizacion conocida");

			//locMgr.GetLastKnownLocation(locationProvider)

			try{
			Log.Debug ("LastKnownLocation","Latitud: "+locMgr.GetLastKnownLocation(locationProvider).Latitude+" Longitud: "+locMgr.GetLastKnownLocation(locationProvider).Longitude);
			}catch(NullReferenceException ex){
			Log.Debug ("LastKnownLocation","No hay LastLocation disponible");
			}
		}
开发者ID:scrafty614,项目名称:XamarinStudio_Example,代码行数:38,代码来源:MainActivity.cs

示例10: OnCreate

        //private double currLatitude;
        //private Location currLongitude;
        protected override void OnCreate(Bundle bundle)
        {
            player = MediaPlayer.Create (this,Resource.Raw.police_alarm);
            base.OnCreate(bundle);
            SetContentView(Resource.Layout.Main);

            //_addressText = FindViewById<TextView>(Resource.Id.textView3);
            _latitudeText = FindViewById<TextView>(Resource.Id.txtLatitude);
            _longitudeText = FindViewById<TextView> (Resource.Id.txtLongitude);
            //_timeText = FindViewById<TextView> (Resource.Id.txtSpeed);
            FindViewById<TextView>(Resource.Id.button1).Click += CallPolice_OnClick;
            FindViewById<TextView> (Resource.Id.button2).Click += alarm_click;

            var sendsos = FindViewById<Button> (Resource.Id.button3);
            //correct on click
            sendsos.Click += (sender, e) => {
                if (_latitudeText.Text == "") {
                    _locationManager = (LocationManager)GetSystemService(LocationService);
                    //var status = _locationManager.GetGpsStatus (null).TimeToFirstFix;
                    //Toast.MakeText (this, status, Toas).Show ();
                    var criteriaForLocationService = new Criteria
                    {
                        Accuracy = Accuracy.Fine
                    };
                    string bestProvider = _locationManager.GetBestProvider(criteriaForLocationService, false);
                    //var acceptableLocationProviders = _locationManager.GetProviders (criteriaForLocationService, true);
                    Location l = _locationManager.GetLastKnownLocation (bestProvider);
                    _latitudeText.Text = l.Latitude.ToString ();
                }
                else{

                    SmsManager.Default.SendTextMessage("1234567890", null,"http://maps.google.com/maps?q="+_currentLocation.Latitude+","+_currentLocation.Longitude, null, null);
                    //SmsManager.Default.SendTextMessage(
                }
            };
            FindViewById<TextView> (Resource.Id.button4).Click += cell_loc;

            var sendsosIntent = FindViewById<Button> (Resource.Id.button3);

            sendsosIntent.Click += (sender, e) => {
                double lat=_currentLocation.Latitude;
                double lon=_currentLocation.Longitude;
                string lo="http://maps.google.com/maps?q="+_currentLocation.Latitude+","+_currentLocation.Longitude+"&mode=driving";
                string locationString = @"				http://maps.google.com/maps/api/staticmap?center=" + _currentLocation.Latitude + "," + _currentLocation.Longitude;
                var i=new Intent(Intent.ActionView,Android.Net.Uri.Parse(lo));
                var intent=new Intent(Intent.ActionView,Android.Net.Uri.Parse("http://maps.google.com/maps?q=loc:56.3245,-3.24567"));

                //StartActivity(i);
                var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
                var smsIntent = new Intent (Intent.ActionSendto, smsUri);
                smsIntent.PutExtra("sms_body",lo);
                StartActivity (smsIntent);

                /*					var smsUri1=Android.Net.Uri.Parse("smsto:378437483");
                var url=Android.Net.Uri.Parse(String.Format("http://maps.google.com/maps?q=\"+_currentLocation.Latitude+\",\"+_currentLocation.Longitude"));
                var smsIntent1=new Intent(Intent.ActionSendto,url);
                StartActivity(smsIntent1);*/

                /*var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
                var smsIntent = new Intent (Intent.ActionSendto, smsUri);
                var ValueType=_currentLocation.Latitude*1E6;
                smsIntent.PutExtra("sms_body",ValueType);
                StartActivity (smsIntent);*/
            };

            InitializeLocationManager();
        }
开发者ID:sonalpathak,项目名称:MySecurity,代码行数:69,代码来源:trial.cs

示例11: Sos_Click

        private void Sos_Click(object sender,EventArgs args)
        {
            //currLatitude = Double.Parse (_currentLocation);
            //currLatitude=string.Format("{0}", _currentLocation.Latitude);
            //currLatitude = _currentLocation.Latitude.ToString();
            //	currLongitude = _currentLocation.Longitude.ToString();
            //	var geouri = Android.Net.Uri.Parse ("geo:",+currLatitude+currLongitude);
            //var mapIntent = new Intent (Intent.ActionView, geoUri);
            //StartActivity (mapIntent);
            if (_latitudeText.Text == "") {
                _locationManager = (LocationManager)GetSystemService(LocationService);
                //var status = _locationManager.GetGpsStatus (null).TimeToFirstFix;
                //Toast.MakeText (this, status, Toas).Show ();
                var criteriaForLocationService = new Criteria
                {
                    Accuracy = Accuracy.Fine
                };
                var acceptableLocationProviders = _locationManager.GetProviders (criteriaForLocationService, true);
                Location l = _locationManager.GetLastKnownLocation ("acceptableLocationProviders");
                _latitudeText.Text = l.Latitude.ToString ();
            } else {
                var smsUri = Android.Net.Uri.Parse("smsto:1234567890");
                var smsIntent = new Intent (Intent.ActionSendto, smsUri);
                smsIntent.PutExtra("please help!",_currentLocation);
                //smsIntent.PutExtra ("sms_body", _currentLocation);
                StartActivity (smsIntent);

            }
        }
开发者ID:sonalpathak,项目名称:MySecurity,代码行数:29,代码来源:trial.cs

示例12: AcquireCurrentGeoLocation

        private void AcquireCurrentGeoLocation()
        {
            _locationManager = (LocationManager)Application.Context.GetSystemService(Context.LocationService);
            // Get the best location provider
            Criteria locationCriteria = new Criteria();
            locationCriteria.Accuracy = Accuracy.Coarse;
            locationCriteria.PowerRequirement = Power.Medium;
            var locationProvider = _locationManager.GetBestProvider(locationCriteria, true);

            if (locationProvider != null)
            {
                CurrentLocation = _locationManager.GetLastKnownLocation(locationProvider);
            }

            _locationManager.RequestLocationUpdates(locationProvider, 0, 0, _locationListener);
        }
开发者ID:nihanli,项目名称:AndroidExperiments,代码行数:16,代码来源:GPSService.cs

示例13: OnActivityCreated

		/// <summary>
		/// Gets the location manager and creates a new Geolocation object with
		/// the user's current location and receives a list from our server
		/// containing all of the nearby users based on that geolocation.
		/// The list is parsed and the profile bios are formatted and placed 
		/// into a string array with the same corresponding index of the string
		/// array of nearby usernames.
		/// </summary>
		/// <param name="savedInstanceState">Bundle.</param>
		public override void OnActivityCreated(Bundle savedInstanceState)
		{
			base.OnActivityCreated(savedInstanceState);

			var ProfileFrame = Activity.FindViewById<View>(Resource.Id.UserProfile);

			// If running on a tablet, then the layout in Resources/Layout-Large will be loaded. 
			// That layout uses fragments, and defines the detailsFrame. We use the visiblity of 
			// detailsFrame as this distinguisher between tablet and phone.
			isDualPane = ProfileFrame != null && ProfileFrame.Visibility == ViewStates.Visible;


			// Get the location manager
			locationManager = (LocationManager) Config.context.GetSystemService(Context.LocationService);
			// Define the criteria how to select the location provider -> use default
			Criteria criteria = new Criteria();
			criteria.Accuracy = Accuracy.Fine;
			provider = locationManager.GetBestProvider(criteria, true);
			Location location = locationManager.GetLastKnownLocation(provider);

            //Create a Geolocation object which handles most of the location related functionality, including server calls
            Geolocation currentLocation = new Geolocation (MainActivity.username, location.Latitude, location.Longitude);

            //Get the list of nearby profiles
            Task<List<Profile>> nearbyProfiles = Task<List<Profile>>.Factory.StartNew(() => 
				{ 
					return currentLocation.GetNearbyUsers().Result;
				});

            //Filter the list of profiles, removing the profile for this user, if it was returned by the server
            nearbyUserslist = new List<Profile>();
			try{
				nearbyUserslist = nearbyProfiles.Result;
				foreach (Profile p in nearbyUserslist){
					if(p.username.Equals(MainActivity.credentials.username)){
						nearbyUserslist.Remove(p);
						break;
					}
				}
			}
			catch(Exception e) {
				string error = e.Message;
				System.Diagnostics.Debug.WriteLine ("\n\nServer offline\n\n" + error);
			}

            //Create the arrays containing the information about the users
			int numUsers = nearbyUserslist.Count;
			string[] nearbyUsers = new string[numUsers];
			nearbyBios = new string[numUsers];

            //Process the information about the nearby users in a formatted string, for display
			for (int i = 0; i < numUsers; i++)
			{
				nearbyUsers [i] = nearbyUserslist [i].username;
				nearbyBios [i] = "⇧ " + nearbyUserslist[i].positive_votes 
					+ "\n⇩ " + nearbyUserslist[i].negative_votes 
					+ "\n\n" + nearbyUserslist [i].gender
					+ "\n\n" + nearbyUserslist [i].bio;
			}
		
            //Set up the adapted to display the list of users
			var adapter = new ArrayAdapter<String>(Activity, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers);
			ListAdapter = adapter;

			if (savedInstanceState != null)
			{
				selectedUserId = savedInstanceState.GetInt("selected_user_id", 0);
			}

			if (isDualPane)
			{
				ListView.ChoiceMode = ChoiceMode.Single;
				ShowProfile(selectedUserId);
			}
		}
开发者ID:Byuunion,项目名称:Senior_project,代码行数:84,代码来源:NearbyUsersFragment.cs

示例14: GPSListener

		public GPSListener(LocationManager lm, SensorManager sm, IWindowManager wm) : base()
		{
			// Get LocationManager
			_locManager = lm;
			_windowManager = wm;

			var locationCriteria = new Criteria ()
			{
				Accuracy = global::Android.Locations.Accuracy.Fine,
				AltitudeRequired = true,
				PowerRequirement = Power.Low
			};

//			locationProvider = _locManager.GetBestProvider(locationCriteria, true);
			locationProvider = LocationManager.GpsProvider;

			if (locationProvider == null)
				throw new Exception("No location provider found");

			List<String> providers = _locManager.GetProviders(true) as List<String>;

			// Loop over the array backwards, and if you get an accurate location, then break out the loop
			GPSLocation loc = null;

			if (providers != null) {
				for (int i = providers.Count - 1; i >= 0; i--) {
					loc = new GPSLocation(_locManager.GetLastKnownLocation(providers[i]));
					if (loc != null) 
						break;
				}
			}

			// If we have an old location, than use this as first location
			if (loc != null)
			{
				_location = new GPSLocation(loc);
			} else {
				_location = new GPSLocation();
			}

			_sensorManager = sm;

			_orientationSensor = _sensorManager.GetDefaultSensor(SensorType.Orientation);
			_accelerometerSensor = _sensorManager.GetDefaultSensor(SensorType.Accelerometer);
		}
开发者ID:WFoundation,项目名称:WF.Player.Android,代码行数:45,代码来源:GPSListenerAndroid.cs

示例15: OnCreate

        /// <summary>
        /// Code to the executed when the activity is created
        /// </summary>
        /// <param name="bundle">Any additional data sent to the activity</param>
		protected override void OnCreate (Bundle bundle)
		{
			base.OnCreate (bundle);

			// Set our view 
			SetContentView (Resource.Layout.message_spinner);

            //Create the spinner for the name of the nearby users
			Spinner spinner = FindViewById<Spinner> (Resource.Id.spinner);
			spinner.ItemSelected += new EventHandler<AdapterView.ItemSelectedEventArgs> (spinner_ItemSelected);

			// Get the location manager
			locationManager = (LocationManager)Config.context.GetSystemService (Context.LocationService);

			// Define the criteria how to select the location provider -> use default
			Criteria criteria = new Criteria ();
			criteria.Accuracy = Accuracy.Fine;
			provider = locationManager.GetBestProvider (criteria, true);
			Location location = locationManager.GetLastKnownLocation (provider);

            //Create a Geolocation object which handles most of the location related functionality, including server calls
			Geolocation currentLocation = new Geolocation (MainActivity.username, location.Latitude, location.Longitude);

            //Get the list of nearby profiles
			Task<List<Profile>> nearbyProfiles = Task<List<Profile>>.Factory.StartNew (() => { 
				return currentLocation.GetNearbyUsers ().Result;
			});

            //Filter the list of profiles, removing the profile for this user, if it was returned by the server
			nearbyUserslist = new List<Profile> ();
			try {
				nearbyUserslist = nearbyProfiles.Result;
				foreach (Profile p in nearbyUserslist) {
					if (p.username.Equals (MainActivity.credentials.username)) {
						nearbyUserslist.Remove (p);
						break;
					}
				}
			} catch (Exception e) {
				string error = e.Message;
				System.Diagnostics.Debug.WriteLine ("\n\nServer offline\n\n" + error);
			}

            //Create an array containing all the usernames of the nearby users
			string[] nearbyUsers = new string[nearbyUserslist.Count];

			for (int i = 0; i < nearbyUserslist.Count; i++) {
				nearbyUsers [i] = nearbyUserslist [i].username;
			}

            //Set up the spinner object to user the array of nearby users
			var adapter = new ArrayAdapter<String> (this, Android.Resource.Layout.SimpleListItemChecked, nearbyUsers);

			adapter.SetDropDownViewResource (Android.Resource.Layout.SimpleSpinnerDropDownItem);
			spinner.Adapter = adapter;

			mMessage = FindViewById<EditText> (Resource.Id.sendMessageTxt);
			mSendMessage = FindViewById<Button> (Resource.Id.btnSendMsg);

			mSendMessage.Click += MSendMessage_Click;
		}
开发者ID:Byuunion,项目名称:Senior_project,代码行数:65,代码来源:MessageSpinner.cs


注:本文中的Android.Locations.LocationManager.GetLastKnownLocation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。