[Doc] Fix unintended links
[platform/core/csapi/tizenfx.git] / src / Tizen.Location / Tizen.Location / Location.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
3  *
4  * Licensed under the Apache License, Version 2.0 (the License);
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an AS IS BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 using System;
18 using System.Collections.Generic;
19
20 namespace Tizen.Location
21 {
22     /// <summary>
23     /// This class contains details of the location requested.
24     /// Includes the functionality to get the distance between locations.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class Location
28     {
29         private double _latitude;
30         private double _longitude;
31         private double _altitude;
32         private double _speed;
33         private double _direction;
34         private double _accuracy;
35         internal int _timestamp;
36
37         /// <summary>
38         /// The default constructor of the Location class.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         public Location()
42         {
43         }
44
45         /// <summary>
46         /// The parameterized constructor of the Location class.
47         /// </summary>
48         /// <since_tizen> 3 </since_tizen>
49         /// <param name="latitude">The latitude component of the device co-ordinate [-90.0 ~ 90.0] \(degrees).</param>
50         /// <param name="longitude">The longitude component of the device co-ordinate[-180.0 ~ 180.0] \(degrees).</param>
51         /// <param name="altitude">The altitude value.</param>
52         /// <param name="accuracy">The accuracy in meters.</param>
53         /// <param name="speed">The device speed.</param>
54         /// <param name="direction">The device direction with respect to the north.</param>
55         /// <param name="timestamp"> Time when the measurement took place.</param>
56         /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
57         public Location(double latitude, double longitude, double altitude, double speed, double direction, double accuracy, int timestamp)
58         {
59             _latitude = latitude;
60             _longitude = longitude;
61             _altitude = altitude;
62             _speed = speed;
63             _direction = direction;
64             _accuracy = accuracy;
65             _timestamp = timestamp;
66         }
67
68         /// <summary>
69         /// The current latitude [-90.0 ~ 90.0] \(degrees).
70         /// </summary>
71         /// <since_tizen> 3 </since_tizen>
72         public double Latitude
73         {
74             get
75             {
76                 Log.Info(Globals.LogTag, "Getting the latitude");
77                 return _latitude;
78             }
79             set
80             {
81                 Log.Info(Globals.LogTag, "Setting the latitude");
82                 if (value >= -90.0 && value <= 90.0)
83                 {
84                     _latitude = value;
85                 }
86                 else
87                 {
88                     Log.Error(Globals.LogTag, "Error setting latitude");
89                     throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
90                 }
91             }
92         }
93
94         /// <summary>
95         /// The current longitude [-180.0 ~ 180.0] \(degrees).
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         public double Longitude
99         {
100             get
101             {
102                 Log.Info(Globals.LogTag, "Getting the longitude");
103                 return _longitude;
104             }
105             set
106             {
107                 Log.Info(Globals.LogTag, "Setting the longitude");
108                 if (value >= -180.0 && value <= 180.0)
109                 {
110                     _longitude = value;
111                 }
112                 else
113                 {
114                     Log.Error(Globals.LogTag, "Error setting longitude");
115                     throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
116                 }
117             }
118         }
119
120         /// <summary>
121         /// The current altitude (meters).
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         public double Altitude
125         {
126             get
127             {
128                 return _altitude;
129             }
130             set
131             {
132                 _altitude = value;
133             }
134         }
135
136         /// <summary>
137         /// The device speed (km/h).
138         /// </summary>
139         /// <since_tizen> 3 </since_tizen>
140         public double Speed
141         {
142             get
143             {
144                 return _speed;
145             }
146             set
147             {
148                 _speed = value;
149             }
150         }
151
152         /// <summary>
153         /// The direction and degrees from the north.
154         /// </summary>
155         /// <since_tizen> 3 </since_tizen>
156         public double Direction
157         {
158             get
159             {
160                 return _direction;
161             }
162             set
163             {
164                 _direction = value;
165             }
166         }
167
168         /// <summary>
169         /// The accuracy.
170         /// </summary>
171         /// <since_tizen> 3 </since_tizen>
172         public double Accuracy
173         {
174             get
175             {
176                 return _accuracy;
177             }
178             set
179             {
180                 _accuracy = value;
181             }
182         }
183
184         /// <summary>
185         /// The time value when the measurement was done.
186         /// </summary>
187         /// <since_tizen> 3 </since_tizen>
188         public DateTime Timestamp
189         {
190             get
191             {
192                 return Interop.ConvertDateTime(_timestamp);
193             }
194             internal set
195             {
196                 Timestamp = value;
197             }
198
199         }
200
201         /// <summary>
202         /// Gets the distance between the two given coordinates.
203         /// </summary>
204         /// <since_tizen> 3 </since_tizen>
205         /// <param name="startLatitude">The latitude of the source location [-90.0 ~ 90.0] \(degrees).</param>
206         /// <param name="startLongitude">The longitude of the source location[-180.0 ~ 180.0] \(degrees).</param>
207         /// <param name="endLatitude">The latitude of the source location [-90.0 ~ 90.0] \(degrees).</param>
208         /// <param name="endLongitude">The longitude of the source location[-180.0 ~ 180.0] \(degrees).</param>
209         /// <returns>Returns the distance between the source and the destination.</returns>
210         /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
211         /// <exception cref="NotSupportedException">Thrown when the location is not supported.</exception>
212         public static double GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
213         {
214             double result;
215             Log.Info(Globals.LogTag, "Calling GetDistanceBetween");
216             int ret = Interop.Location.GetDistanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, out result);
217             if (((LocationError)ret != LocationError.None))
218             {
219                 Log.Error(Globals.LogTag, "Error getting single distance information ," + (LocationError)ret);
220                 throw LocationErrorFactory.ThrowLocationException(ret);
221             }
222             return result;
223         }
224
225         /// <summary>
226         /// Gets the distance between the current and the specified location.
227         /// </summary>
228         /// <since_tizen> 3 </since_tizen>
229         /// <param name="location"> The location object to which distance is to be calculated.</param>
230         /// <returns>Returns the distance to the specified location.</returns>
231         /// <exception cref="ArgumentException">Thrown when an invalid argument is used.</exception>
232         /// <exception cref="NotSupportedException">Thrown when the location is not supported.</exception>
233         public double GetDistanceTo(Location location)
234         {
235             double result;
236             Log.Info(Globals.LogTag, "Calling GetDistanceTo");
237             int ret = Interop.Location.GetDistanceBetween(this.Latitude, this.Longitude, location.Latitude, location.Longitude, out result);
238             if (((LocationError)ret != LocationError.None))
239             {
240                 Log.Error(Globals.LogTag, "Error getting distance information to the specifed location," + (LocationError)ret);
241                 throw LocationErrorFactory.ThrowLocationException(ret);
242             }
243             return result;
244         }
245     }
246 }