-
Notifications
You must be signed in to change notification settings - Fork 74
/
GeoLoc.cs
57 lines (51 loc) · 1.78 KB
/
GeoLoc.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
namespace Redis.OM.Modeling
{
/// <summary>
/// A structure representing a point on the globe by it's longitude and latitude.
/// </summary>
public struct GeoLoc
{
/// <summary>
/// Initializes a new instance of the <see cref="GeoLoc"/> struct.
/// </summary>
/// <param name="longitude">The longitude.</param>
/// <param name="latitude">The latitude.</param>
public GeoLoc(double longitude, double latitude)
{
Longitude = longitude;
Latitude = latitude;
}
/// <summary>
/// Gets or sets the longitude.
/// </summary>
public double Longitude { get; set; }
/// <summary>
/// Gets or sets the latitude.
/// </summary>
public double Latitude { get; set; }
/// <summary>
/// Parses a Geolocation from a string.
/// </summary>
/// <param name="geolocString">the string representation of a geoloc.</param>
/// <returns>a geoloc parsed from the string.</returns>
/// <exception cref="ArgumentException">thrown if the geoloc could not be parsed from the string.</exception>
public static GeoLoc Parse(string geolocString)
{
var arr = geolocString.Split(',');
if (arr.Length == 2)
{
if (double.TryParse(arr[0], out var lon) && double.TryParse(arr[1], out var lat))
{
return new GeoLoc(lon, lat);
}
}
throw new ArgumentException("GeoLoc string must be a string in the format longitude,latitude");
}
/// <inheritdoc/>
public override string ToString()
{
return $"{Longitude},{Latitude}";
}
}
}