4f983b126efed43d85f42e3d1c8c6c7856e90a5f
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Tizen.Location / Location.cs
1 // Copyright 2016 by Samsung Electronics, Inc.,
2 //
3 // This software is the confidential and proprietary information
4 // of Samsung Electronics, Inc. ("Confidential Information"). You
5 // shall not disclose such Confidential Information and shall use
6 // it only in accordance with the terms of the license agreement
7 // you entered into with Samsung.
8
9 using System;
10 using System.Collections.Generic;
11
12 namespace Tizen.Location
13 {
14     /// <summary>
15     /// A class which contains the details of the location rrequested.
16     /// Includes the functionality to get the distance between locations.
17     /// </summary>
18     public class Location
19     {
20         private double _altitude;
21         private double _latitude;
22         private double _longitude;
23         private double _direction;
24         private double _speed;
25         private double _horizontal;
26         internal int _timestamp;
27
28         /// <summary>
29         /// The default constructor of Location Class.
30         /// </summary>
31         public Location()
32         {
33         }
34
35         /// <summary>
36         /// The parameterized constructor of Location Class.
37         /// <param name="latitude"> Latitude component of the device co-ordinate [-90.0 ~ 90.0] (degrees).</param>
38         /// <param name="longitude"> Longitude component of the device co-ordinate[-180.0 ~ 180.0] (degrees).</param>
39         /// <param name="altitude"> Altitude value.</param>
40         /// <param name="horizontalAccuracy"> Horizontal Accuracy in meters.</param>
41         /// <param name="speed"> Devie Speed.</param>
42         /// <param name="direction"> Device direction with respect to north.</param>
43         /// <param name="timestamp"> Time when the measurement took place.</param>
44         /// </summary>
45         public Location(double latitude, double longitude, double altitude, double horizontalAccuracy, double direction, double speed, int timestamp)
46         {
47             _latitude = latitude;
48             _longitude = longitude;
49             _altitude = altitude;
50             _horizontal = horizontalAccuracy;
51             _direction = direction;
52             _speed = speed;
53             _timestamp = timestamp;
54         }
55
56         /// <summary>
57         /// The current altitude (meters).
58         /// </summary>
59         public double Altitude
60         {
61             get
62             {
63                 return _altitude;
64             }
65             set
66             {
67                 _altitude = value;
68             }
69         }
70
71         /// <summary>
72         /// The current latitude [-90.0 ~ 90.0] (degrees).
73         /// </summary>
74         public double Latitude
75         {
76             get
77             {
78                 return _latitude;
79             }
80             set
81             {
82                 _latitude = value;
83             }
84         }
85
86         /// <summary>
87         /// The current longitude [-180.0 ~ 180.0] (degrees).
88         /// </summary>
89         public double Longitude
90         {
91             get
92             {
93                 return _longitude;
94             }
95             set
96             {
97                 _longitude = value;
98             }
99         }
100
101         /// <summary>
102         /// The direction, degrees from the north.
103         /// </summary>
104         public double Direction
105         {
106             get
107             {
108                 return _direction;
109             }
110             set
111             {
112                 _direction = value;
113             }
114         }
115
116         /// <summary>
117         /// The Device Speed (km/h).
118         /// </summary>
119         public double Speed
120         {
121             get
122             {
123                 return _speed;
124             }
125             set
126             {
127                 _speed = value;
128             }
129         }
130
131         /// <summary>
132         /// The horizontal accuracy.
133         /// </summary>
134         public double HorizontalAccuracy
135         {
136             get
137             {
138                 return _horizontal;
139             }
140             set
141             {
142                 _horizontal = value;
143             }
144         }
145
146         /// <summary>
147         /// The time value when the measurement was done.
148         /// </summary>
149         public DateTime Timestamp
150         {
151             get
152             {
153                 return Interop.ConvertDateTime(_timestamp);
154             }
155             internal set
156             {
157                 Timestamp = value;
158             }
159
160         }
161
162         /// <summary>
163         /// Gets the distance between the two given coordinates.
164         /// </summary>
165         /// <param name="startLatitude"> The latitude of the source location [-90.0 ~ 90.0] (degrees).</param>
166         /// <param name="startLongitude"> The Longitude of the source location[-180.0 ~ 180.0] (degrees).</param>
167         /// <param name="endLatitude"> The latitude of the source location [-90.0 ~ 90.0] (degrees).</param>
168         /// <param name="endLongitude"> The longitude of the source location[-180.0 ~ 180.0] (degrees).</param>
169         /// <returns>Returns the distance between source and destination.</returns>
170         public static double GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
171         {
172             double result;
173             Log.Info(Globals.LogTag, "Calling GetDistanceBetween");
174             int ret = Interop.Location.GetDistanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, out result);
175             if (((LocationError)ret != LocationError.None))
176             {
177                 Log.Error(Globals.LogTag, "Error getting single distance information ," + (LocationError)ret);
178                 LocationErrorFactory.ThrowLocationException(ret);
179             }
180             return result;
181         }
182
183         /// <summary>
184         /// Gets the distance between the current and specified location.
185         /// </summary>
186         /// <param name="location"> The location object to which distance is to be calculated.</param>
187         /// <returns>Returns the distance to the specified location.</returns>
188         public double GetDistanceTo(Location location)
189         {
190             double result;
191             Log.Info(Globals.LogTag, "Calling GetDistanceTo");
192             int ret = Interop.Location.GetDistanceBetween(this.Latitude, this.Longitude, location.Latitude, location.Longitude, out result);
193             if (((LocationError)ret != LocationError.None))
194             {
195                 Log.Error(Globals.LogTag, "Error getting distance information to the specifed location," + (LocationError)ret);
196                 LocationErrorFactory.ThrowLocationException(ret);
197             }
198             return result;
199         }
200     }
201 }