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 /// A class which contains the details of the location rrequested.
24 /// Includes the functionality to get the distance between locations.
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;
37 /// The default constructor of Location Class.
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>
53 public Location(double latitude, double longitude, double altitude, double horizontalAccuracy, double direction, double speed, int timestamp)
56 _longitude = longitude;
58 _horizontal = horizontalAccuracy;
59 _direction = direction;
61 _timestamp = timestamp;
65 /// The current altitude (meters).
67 public double Altitude
80 /// The current latitude [-90.0 ~ 90.0] (degrees).
82 public double Latitude
95 /// The current longitude [-180.0 ~ 180.0] (degrees).
97 public double Longitude
110 /// The direction, degrees from the north.
112 public double Direction
125 /// The Device Speed (km/h).
140 /// The horizontal accuracy.
142 public double HorizontalAccuracy
155 /// The time value when the measurement was done.
157 public DateTime Timestamp
161 return Interop.ConvertDateTime(_timestamp);
171 /// Gets the distance between the two given coordinates.
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)
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))
185 Log.Error(Globals.LogTag, "Error getting single distance information ," + (LocationError)ret);
186 LocationErrorFactory.ThrowLocationException(ret);
192 /// Gets the distance between the current and specified location.
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)
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))
203 Log.Error(Globals.LogTag, "Error getting distance information to the specifed location," + (LocationError)ret);
204 LocationErrorFactory.ThrowLocationException(ret);