Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void Setup()
- {
- if (this.geolocator != null)
- return;
- this.geolocator = new Geolocator (this) { DesiredAccuracy = 50 };
- if (!this.geolocator.IsListening)
- {
- if (!this.geolocator.IsGeolocationAvailable || !this.geolocator.IsGeolocationEnabled)
- {
- #if DEBUG
- Toast.MakeText (this, "Geolocation is unavailable", ToastLength.Long).Show();
- #endif
- return;
- }
- this.geolocator.StartListening (minTime: 30000, minDistance: 0);
- }
- else
- {
- this.geolocator.StopListening();
- }
- //this.geolocator.PositionError += OnListeningError;
- //this.geolocator.PositionChanged += OnPositionChanged;
- }
- public void OnGetPosition (Activity act)
- {
- Setup();
- this.cancelSource = new CancellationTokenSource();
- this.geolocator.GetPositionAsync (timeout: 10000, cancelToken: this.cancelSource.Token)
- .ContinueWith (t => act.RunOnUiThread (() =>
- {
- if(t.IsFaulted == false && t.IsCanceled == false)
- {
- CurrentLocation = t.Result;
- geolocator.StopListening();
- }
- }));
- }
Advertisement
Add Comment
Please, Sign In to add comment