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