コード例 #1
0
        /// <summary>
        /// Attempts the start the geowatcher.
        /// </summary>
        private void TryStartGps()
        {
            bool permission = true;

            if (GeoPositionWatcher is GeoCoordinateWatcher)
            {
                permission = (GeoPositionWatcher as GeoCoordinateWatcher).Permission != GeoPositionPermission.Denied;
            }
#if WINDOWS_PHONE
            if (permission && Visible && Map != null && IsEnabled && GeoPositionWatcher != null)
            {
                GeoPositionWatcher.Start(true); //TryStart's behavior is not consistent across WP OS versions
            }
            if (GeoPositionWatcher != null && GeoPositionWatcher.Position != null &&
                GeoPositionWatcher.Position.Location != null && !GeoPositionWatcher.Position.Location.IsUnknown)
            {
                UpdatePosition(GeoPositionWatcher.Position);
            }
#else
            bool result = false;
            if (permission && Visible && Map != null && IsEnabled && GeoPositionWatcher != null)
            {
                result = GeoPositionWatcher.TryStart(true, TimeSpan.FromSeconds(10));
            }
            if (result && GeoPositionWatcher != null && GeoPositionWatcher.Position != null &&
                GeoPositionWatcher.Position.Location != null && !GeoPositionWatcher.Position.Location.IsUnknown)
            {
                UpdatePosition(GeoPositionWatcher.Position);
            }
#endif
        }
コード例 #2
0
 /// <summary>
 /// Override to know when a layer's <see cref="Map"/> property changes.
 /// </summary>
 /// <param name="oldValue">Old map</param>
 /// <param name="newValue">New map</param>
 protected override void OnMapChanged(Map oldValue, Map newValue)
 {
     base.OnMapChanged(oldValue, newValue);
     if (oldValue != null)
     {
         oldValue.PropertyChanged -= map_PropertyChanged;
     }
     if (newValue != null)
     {
         newValue.PropertyChanged += map_PropertyChanged;
         if (GeoPositionWatcher != null)
         {
             TryStartGps();
         }
     }
     else if (GeoPositionWatcher != null)
     {
         GeoPositionWatcher.Stop();
     }
 }