Guest User

Untitled

a guest
Jun 19th, 2018
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.30 KB | None | 0 0
  1. using System;
  2. using System.Device.Location;
  3.  
  4. using Microsoft.Devices.Sensors;
  5. using Microsoft.Phone.Controls;
  6. using Microsoft.Xna.Framework;
  7.  
  8. namespace map_5_
  9. {
  10.     public partial class MainPage : PhoneApplicationPage
  11.     {
  12.         private Accelerometer myAccel;
  13.  
  14.         private Vector3 currentValues;
  15.  
  16.         private GeoCoordinateWatcher myGeoWatcher;
  17.  
  18.         public MainPage()
  19.         {
  20.             InitializeComponent();
  21.  
  22.             myAccel = new Accelerometer();
  23.             this.myAccel.CurrentValueChanged +=
  24.                 new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(myAccel_CurrentValueChanged);
  25.             myAccel.Start();
  26.             currentValues = myAccel.CurrentValue.Acceleration;
  27.  
  28.             myGeoWatcher=new GeoCoordinateWatcher();
  29.             this.myGeoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(myGeoWatcher_StatusChanged);
  30.             myGeoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myGeoWatcher_PositionChanged);
  31.             myGeoWatcher.TryStart(false, TimeSpan.FromSeconds(60));
  32.         }
  33.  
  34.         void myGeoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
  35.         {
  36.             switch (e.Status)
  37.             {
  38.                 case GeoPositionStatus.Disabled:
  39.                     if (myGeoWatcher.Permission == GeoPositionPermission.Denied)
  40.                     {
  41.                         GeoStatus.Text = "Сервис выключен";
  42.                     }
  43.                     else
  44.                     {
  45.                         GeoStatus.Text = "На этом устройстве сервис недоступен";
  46.                     }
  47.                     break;
  48.                 case GeoPositionStatus.Initializing:
  49.                     GeoStatus.Text = "Сервис инициализируется";
  50.                     break;
  51.                 case GeoPositionStatus.NoData:
  52.                     GeoStatus.Text = "Данные о месположении недоступны";
  53.                     break;
  54.                 case GeoPositionStatus.Ready:
  55.                     GeoStatus.Text = "Данные о местоположении доступны";
  56.                     break;
  57.             }
  58.  
  59.         }
  60.  
  61.         void myGeoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
  62.         {
  63.             map1.Center = e.Position.Location;
  64.         }
  65.  
  66.         void myAccel_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
  67.         {
  68.             if (myAccel.IsDataValid)
  69.             {
  70.                 var deltaZ = (currentValues - e.SensorReading.Acceleration).Z;
  71.                 var Z = e.SensorReading.Acceleration.Z;
  72.                 currentValues = e.SensorReading.Acceleration;
  73.                 if (Z < 0 && deltaZ > 0)
  74.                 {
  75.                     Dispatcher.BeginInvoke(this.HandleZoomIn);
  76.                 }
  77.                 if (Z > 0 && deltaZ < 0)
  78.                 {
  79.                     Dispatcher.BeginInvoke(this.HandleZoomOut);
  80.                 }
  81.             }
  82.         }
  83.  
  84.         private void HandleZoomIn()
  85.         {
  86.             map1.ZoomLevel += 1;
  87.         }
  88.  
  89.         private void HandleZoomOut()
  90.         {
  91.             map1.ZoomLevel -= 1;
  92.         }
  93.  
  94.     }
  95. }
Add Comment
Please, Sign In to add comment