/*
* Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using System.Collections.Generic;
namespace Tizen.Location
{
///
/// This class contains details of the location requested.
/// Includes the functionality to get the distance between locations.
///
/// 3
public class Location
{
private double _latitude;
private double _longitude;
private double _altitude;
private double _speed;
private double _direction;
private double _accuracy;
internal int _timestamp;
///
/// The default constructor of the Location class.
///
/// 3
public Location()
{
}
///
/// The parameterized constructor of the Location class.
///
/// 3
/// The latitude component of the device co-ordinate [-90.0 ~ 90.0] \(degrees).
/// The longitude component of the device co-ordinate[-180.0 ~ 180.0] \(degrees).
/// The altitude value.
/// The accuracy in meters.
/// The device speed.
/// The device direction with respect to the north.
/// Time when the measurement took place.
/// Thrown when an invalid argument is used.
public Location(double latitude, double longitude, double altitude, double speed, double direction, double accuracy, int timestamp)
{
_latitude = latitude;
_longitude = longitude;
_altitude = altitude;
_speed = speed;
_direction = direction;
_accuracy = accuracy;
_timestamp = timestamp;
}
///
/// The current latitude [-90.0 ~ 90.0] \(degrees).
///
/// 3
public double Latitude
{
get
{
Log.Info(Globals.LogTag, "Getting the latitude");
return _latitude;
}
set
{
Log.Info(Globals.LogTag, "Setting the latitude");
if (value >= -90.0 && value <= 90.0)
{
_latitude = value;
}
else
{
Log.Error(Globals.LogTag, "Error setting latitude");
throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
}
}
}
///
/// The current longitude [-180.0 ~ 180.0] \(degrees).
///
/// 3
public double Longitude
{
get
{
Log.Info(Globals.LogTag, "Getting the longitude");
return _longitude;
}
set
{
Log.Info(Globals.LogTag, "Setting the longitude");
if (value >= -180.0 && value <= 180.0)
{
_longitude = value;
}
else
{
Log.Error(Globals.LogTag, "Error setting longitude");
throw LocationErrorFactory.ThrowLocationException((int)LocationError.InvalidParameter);
}
}
}
///
/// The current altitude (meters).
///
/// 3
public double Altitude
{
get
{
return _altitude;
}
set
{
_altitude = value;
}
}
///
/// The device speed (km/h).
///
/// 3
public double Speed
{
get
{
return _speed;
}
set
{
_speed = value;
}
}
///
/// The direction and degrees from the north.
///
/// 3
public double Direction
{
get
{
return _direction;
}
set
{
_direction = value;
}
}
///
/// The accuracy.
///
/// 3
public double Accuracy
{
get
{
return _accuracy;
}
set
{
_accuracy = value;
}
}
///
/// The time value when the measurement was done.
///
/// 3
public DateTime Timestamp
{
get
{
return Interop.ConvertDateTime(_timestamp);
}
internal set
{
Timestamp = value;
}
}
///
/// Gets the distance between the two given coordinates.
///
/// 3
/// The latitude of the source location [-90.0 ~ 90.0] \(degrees).
/// The longitude of the source location[-180.0 ~ 180.0] \(degrees).
/// The latitude of the source location [-90.0 ~ 90.0] \(degrees).
/// The longitude of the source location[-180.0 ~ 180.0] \(degrees).
/// Returns the distance between the source and the destination.
/// Thrown when an invalid argument is used.
/// Thrown when the location is not supported.
public static double GetDistanceBetween(double startLatitude, double startLongitude, double endLatitude, double endLongitude)
{
double result;
Log.Info(Globals.LogTag, "Calling GetDistanceBetween");
int ret = Interop.Location.GetDistanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, out result);
if (((LocationError)ret != LocationError.None))
{
Log.Error(Globals.LogTag, "Error getting single distance information ," + (LocationError)ret);
throw LocationErrorFactory.ThrowLocationException(ret);
}
return result;
}
///
/// Gets the distance between the current and the specified location.
///
/// 3
/// The location object to which distance is to be calculated.
/// Returns the distance to the specified location.
/// Thrown when an invalid argument is used.
/// Thrown when the location is not supported.
public double GetDistanceTo(Location location)
{
double result;
Log.Info(Globals.LogTag, "Calling GetDistanceTo");
int ret = Interop.Location.GetDistanceBetween(this.Latitude, this.Longitude, location.Latitude, location.Longitude, out result);
if (((LocationError)ret != LocationError.None))
{
Log.Error(Globals.LogTag, "Error getting distance information to the specifed location," + (LocationError)ret);
throw LocationErrorFactory.ThrowLocationException(ret);
}
return result;
}
}
}