Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using Android.App;
- using Android.Content;
- using Android.Runtime;
- using Android.Views;
- using Android.Widget;
- using Android.OS;
- using Android.Locations;
- using System.Collections.Generic;
- using Android.Util;
- using System.Linq;
- namespace LoyaltyCheckInAndroid
- {
- [Activity(Label = "LoyaltyCheckIn", MainLauncher = true, Icon = "@drawable/icon")]
- public class MainActivity : Activity, ILocationListener
- {
- Location _currentLocation;
- LocationManager _locationManager;
- string _locationProvider;
- TextView txtLatitude;
- TextView txtLongitude;
- protected override void OnCreate(Bundle bundle)
- {
- base.OnCreate(bundle);
- SetContentView(Resource.Layout.Main);
- txtLatitude = FindViewById<TextView>(Resource.Id.Latitude);
- txtLongitude = FindViewById<TextView>(Resource.Id.Longitude);
- FindViewById<TextView>(Resource.Id.btnCheckIn).Click += BtnCheckIn_OnClick;
- InitializeLocationManager();
- }
- protected override void OnResume()
- {
- base.OnResume();
- string Provider = LocationManager.GpsProvider;
- if (_locationManager.IsProviderEnabled(Provider))
- {
- _locationManager.RequestLocationUpdates(Provider, 2000, 1, this);
- }
- else
- {
- }
- }
- protected override void OnPause()
- {
- base.OnPause();
- _locationManager.RemoveUpdates(this);
- }
- void BtnCheckIn_OnClick(object sender, EventArgs eventArgs)
- {
- if (_currentLocation == null)
- {
- txtLongitude.Text = "???";
- txtLatitude.Text = "???";
- return;
- }
- //ovde prati za foursqre
- txtLatitude.Text = _currentLocation.Latitude.ToString();
- txtLongitude.Text = _currentLocation.Longitude.ToString();
- }
- void InitializeLocationManager()
- {
- _locationManager = GetSystemService(Context.LocationService) as LocationManager;
- Criteria locationCriteria = new Criteria();
- locationCriteria.Accuracy = Accuracy.Coarse;
- locationCriteria.PowerRequirement = Power.Medium;
- _locationProvider = _locationManager.GetBestProvider(locationCriteria, true);
- if (_locationProvider != null)
- {
- _locationManager.RequestLocationUpdates(_locationProvider, 2000, 1, this);
- }
- else
- {
- }
- }
- public void OnLocationChanged(Location location)
- {
- _currentLocation = location;
- }
- public void OnProviderDisabled(string provider) { }
- public void OnProviderEnabled(string provider) { }
- public void OnStatusChanged(string provider, Availability status, Bundle extras) { }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement