mirror of
https://github.com/farcasclaudiu/myfriendsaround.git
synced 2026-06-29 13:02:05 +03:00
1f79fa6349
- LocationString on update - web app markers icons
76 lines
2.4 KiB
C#
76 lines
2.4 KiB
C#
using System;
|
|
using System.Net;
|
|
using System.Windows;
|
|
using System.Windows.Controls;
|
|
using System.Windows.Documents;
|
|
using System.Windows.Ink;
|
|
using System.Windows.Input;
|
|
using System.Windows.Media;
|
|
using System.Windows.Media.Animation;
|
|
using System.Windows.Shapes;
|
|
using Microsoft.Devices;
|
|
using MyFriendsAround.WP7.Model;
|
|
using System.Device.Location;
|
|
|
|
namespace MyFriendsAround.WP7.Service
|
|
{
|
|
public class LocationService : ILocationService
|
|
{
|
|
|
|
private IGeoPositionWatcher<GeoCoordinate> _gpsWatcher;
|
|
public event EventHandler<LocationChangedEventArgs> LocationChanged;
|
|
public event EventHandler<LocationStatusEventArgs> StatusChanged;
|
|
public Location CurrentLocation { get; private set; }
|
|
|
|
|
|
public LocationService()
|
|
{
|
|
if (Microsoft.Devices.Environment.DeviceType == DeviceType.Emulator)
|
|
{
|
|
_gpsWatcher = new GpsEmulatorClient.GeoCoordinateWatcher();
|
|
}
|
|
else
|
|
{
|
|
_gpsWatcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High)
|
|
{
|
|
MovementThreshold = 10
|
|
};
|
|
}
|
|
|
|
_gpsWatcher.PositionChanged += new EventHandler<GeoPositionChangedEventArgs<GeoCoordinate>>(watcher_PositionChanged);
|
|
_gpsWatcher.StatusChanged += new EventHandler<GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
|
|
}
|
|
|
|
private void watcher_StatusChanged(object sender, GeoPositionStatusChangedEventArgs args)
|
|
{
|
|
//
|
|
if (StatusChanged != null)
|
|
StatusChanged(sender, new LocationStatusEventArgs(args.Status));
|
|
}
|
|
|
|
private void watcher_PositionChanged(object sender, GeoPositionChangedEventArgs<GeoCoordinate> args)
|
|
{
|
|
if (LocationChanged != null)
|
|
LocationChanged(sender, new LocationChangedEventArgs(
|
|
new Location(args.Position.Location.Latitude, args.Position.Location.Longitude, args.Position.Timestamp)
|
|
));
|
|
}
|
|
|
|
public Location GetCurrentLocation()
|
|
{
|
|
return CurrentLocation;
|
|
}
|
|
|
|
public void Start()
|
|
{
|
|
_gpsWatcher.Start();
|
|
}
|
|
|
|
public void Stop()
|
|
{
|
|
_gpsWatcher.Stop();
|
|
}
|
|
|
|
}
|
|
}
|