Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Device.Location;
- using Microsoft.Devices.Sensors;
- using Microsoft.Phone.Controls;
- using Microsoft.Xna.Framework;
- namespace map_5_
- {
- public partial class MainPage : PhoneApplicationPage
- {
- private Accelerometer myAccel;
- private Vector3 currentValues;
- private GeoCoordinateWatcher myGeoWatcher;
- public MainPage()
- {
- InitializeComponent();
- myAccel = new Accelerometer();
- this.myAccel.CurrentValueChanged +=
- new EventHandler<SensorReadingEventArgs<AccelerometerReading>>(myAccel_CurrentValueChanged);
- myAccel.Start();
- currentValues = myAccel.CurrentValue.Acceleration;
- myGeoWatcher=new GeoCoordinateWatcher();
- this.myGeoWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(myGeoWatcher_StatusChanged);
- myGeoWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(myGeoWatcher_PositionChanged);
- myGeoWatcher.TryStart(false, TimeSpan.FromSeconds(60));
- }
- void myGeoWatcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs e)
- {
- switch (e.Status)
- {
- case GeoPositionStatus.Disabled:
- if (myGeoWatcher.Permission == GeoPositionPermission.Denied)
- {
- GeoStatus.Text = "Сервис выключен";
- }
- else
- {
- GeoStatus.Text = "На этом устройстве сервис недоступен";
- }
- break;
- case GeoPositionStatus.Initializing:
- GeoStatus.Text = "Сервис инициализируется";
- break;
- case GeoPositionStatus.NoData:
- GeoStatus.Text = "Данные о месположении недоступны";
- break;
- case GeoPositionStatus.Ready:
- GeoStatus.Text = "Данные о местоположении доступны";
- break;
- }
- }
- void myGeoWatcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> e)
- {
- map1.Center = e.Position.Location;
- }
- void myAccel_CurrentValueChanged(object sender, SensorReadingEventArgs<AccelerometerReading> e)
- {
- if (myAccel.IsDataValid)
- {
- var deltaZ = (currentValues - e.SensorReading.Acceleration).Z;
- var Z = e.SensorReading.Acceleration.Z;
- currentValues = e.SensorReading.Acceleration;
- if (Z < 0 && deltaZ > 0)
- {
- Dispatcher.BeginInvoke(this.HandleZoomIn);
- }
- if (Z > 0 && deltaZ < 0)
- {
- Dispatcher.BeginInvoke(this.HandleZoomOut);
- }
- }
- }
- private void HandleZoomIn()
- {
- map1.ZoomLevel += 1;
- }
- private void HandleZoomOut()
- {
- map1.ZoomLevel -= 1;
- }
- }
- }
Add Comment
Please, Sign In to add comment