2 * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Collections.Generic;
20 namespace Tizen.Location
23 /// This class contains details of the location requested.
24 /// Includes the functionality to get the distance between locations.
26 /// <since_tizen> 3 </since_tizen>
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;
38 /// The default constructor of the Location class.
40 /// <since_tizen> 3 </since_tizen>
46 /// The parameterized constructor of the Location class.
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)
60 _longitude = longitude;
63 _direction = direction;
65 _timestamp = timestamp;
69 /// The current latitude [-90.0 ~ 90.0] \(degrees).
71 /// <since_tizen> 3 </since_tizen>
72 public double Latitude
76 Log.Info(Globals.LogTag, "Getting the latitude");
81 Log.Info(Globals.LogTag, "Setting the latitude");
82 if (value >= -90.0 && value <= 90.0)
88 Log.Error(Globals.LogTag, "Error setting latitude");
89 throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
95 /// The current longitude [-180.0 ~ 180.0] \(degrees).
97 /// <since_tizen> 3 </since_tizen>
98 public double Longitude
102 Log.Info(Globals.LogTag, "Getting the longitude");
107 Log.Info(Globals.LogTag, "Setting the longitude");
108 if (value >= -180.0 && value <= 180.0)
114 Log.Error(Globals.LogTag, "Error setting longitude");
115 throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
121 /// The current altitude (meters).
123 /// <since_tizen> 3 </since_tizen>
124 public double Altitude
137 /// The device speed (km/h).
139 /// <since_tizen> 3 </since_tizen>
153 /// The direction and degrees from the north.
155 /// <since_tizen> 3 </since_tizen>
156 public double Direction
171 /// <since_tizen> 3 </since_tizen>
172 public double Accuracy
185 /// The time value when the measurement was done.
187 /// <since_tizen> 3 </since_tizen>
188 public DateTime Timestamp
192 return Interop.ConvertDateTime(_timestamp);
202 /// Gets the distance between the two given coordinates.
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)
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))
219 Log.Error(Globals.LogTag, "Error getting single distance information ," + (LocationError)ret);
220 throw LocationErrorFactory.ThrowLocationException(ret);
226 /// Gets the distance between the current and the specified location.
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)
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))
240 Log.Error(Globals.LogTag, "Error getting distance information to the specifed location," + (LocationError)ret);
241 throw LocationErrorFactory.ThrowLocationException(ret);