-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Geofence.cs
37 lines (32 loc) · 1.32 KB
/
Geofence.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Algorithms.Other
{
public class Geofence
{
public double Latitude { get; set; }
public double Longitude { get; set; }
public double RadiusInMeters { get; set; }
public Geofence(double latitude, double longitude, double radiusInMeters)
{
Latitude = latitude;
Longitude = longitude;
RadiusInMeters = radiusInMeters;
}
/// <summary>
/// Checks whether the provided user location (latitude and longitude) is within the geofence boundary.
/// The geofence is defined by a center point (latitude, longitude) and a radius in meters.
/// </summary>
/// <param name="userLatitude">The latitude of the user's current location.</param>
/// <param name="userLongitude">The longitude of the user's current location.</param>
/// <returns>Returns true if the user is inside the geofence, otherwise returns false.</returns>
public bool IsInside(double userLatitude, double userLongitude)
{
double distance = GeoLocation.CalculateDistanceFromLatLng(Latitude, Longitude, userLatitude, userLongitude);
return distance <= RadiusInMeters;
}
}
}