summaryrefslogtreecommitdiff
path: root/Xamarin.Forms.Maps.UWP
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-11-22 13:02:12 (GMT)
committerRui Marinho <me@ruimarinho.net>2016-11-22 13:02:12 (GMT)
commit23fd0b63950864c30e01465b0e1adfc2fd35c700 (patch)
treef3e8494d147ffe6ba8c34e013858770e1356d6ed /Xamarin.Forms.Maps.UWP
parent55b8a43b5be42e522a98310eb09a278fcd21ab97 (diff)
downloadxamarin-forms-23fd0b63950864c30e01465b0e1adfc2fd35c700.zip
xamarin-forms-23fd0b63950864c30e01465b0e1adfc2fd35c700.tar.gz
xamarin-forms-23fd0b63950864c30e01465b0e1adfc2fd35c700.tar.bz2
[UWP]Track user location when IsShowingUser enabled (#556)
Diffstat (limited to 'Xamarin.Forms.Maps.UWP')
-rw-r--r--Xamarin.Forms.Maps.UWP/MapRenderer.cs23
1 files changed, 21 insertions, 2 deletions
diff --git a/Xamarin.Forms.Maps.UWP/MapRenderer.cs b/Xamarin.Forms.Maps.UWP/MapRenderer.cs
index f8a4c87..842864b 100644
--- a/Xamarin.Forms.Maps.UWP/MapRenderer.cs
+++ b/Xamarin.Forms.Maps.UWP/MapRenderer.cs
@@ -6,6 +6,7 @@ using System.Linq;
using System.Threading.Tasks;
using Windows.Devices.Geolocation;
using Windows.UI;
+using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls.Maps;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Shapes;
@@ -85,6 +86,9 @@ namespace Xamarin.Forms.Maps.WinRT
{
_disposed = true;
+ _timer?.Stop();
+ _timer = null;
+
MessagingCenter.Unsubscribe<Map, MapSpan>(this, "MapMoveToRegion");
if (Element != null)
@@ -96,6 +100,7 @@ namespace Xamarin.Forms.Maps.WinRT
bool _disposed;
bool _firstZoomLevelChangeFired;
Ellipse _userPositionCircle;
+ DispatcherTimer _timer;
void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
{
@@ -155,8 +160,9 @@ namespace Xamarin.Forms.Maps.WinRT
Control.Children.Add(new PushPin(pin));
}
- async Task UpdateIsShowingUser()
+ async Task UpdateIsShowingUser(bool moveToLocation = true)
{
+
if (Element.IsShowingUser)
{
var myGeolocator = new Geolocator();
@@ -165,11 +171,24 @@ namespace Xamarin.Forms.Maps.WinRT
{
var userPosition = await myGeolocator.GetGeopositionAsync();
if (userPosition?.Coordinate != null)
- LoadUserPosition(userPosition.Coordinate, true);
+ LoadUserPosition(userPosition.Coordinate, moveToLocation);
+ }
+
+ if (_timer == null)
+ {
+ _timer = new DispatcherTimer();
+ _timer.Tick += async (s, o) => await UpdateIsShowingUser(moveToLocation: false);
+ _timer.Interval = TimeSpan.FromSeconds(15);
}
+
+ if (!_timer.IsEnabled)
+ _timer.Start();
}
else if (_userPositionCircle != null && Control.Children.Contains(_userPositionCircle))
+ {
+ _timer?.Stop();
Control.Children.Remove(_userPositionCircle);
+ }
}
async Task MoveToRegion(MapSpan span, MapAnimationKind animation = MapAnimationKind.Bow)