diff options
Diffstat (limited to 'src/FLoc_MathUtils.cpp')
-rw-r--r-- | src/FLoc_MathUtils.cpp | 29 |
1 files changed, 28 insertions, 1 deletions
diff --git a/src/FLoc_MathUtils.cpp b/src/FLoc_MathUtils.cpp index 25c2b6a..dc6042b 100644 --- a/src/FLoc_MathUtils.cpp +++ b/src/FLoc_MathUtils.cpp @@ -23,6 +23,7 @@ */ #include <math.h> +#include <FBaseDouble.h> #include <FBaseSysLog.h> #include <FBaseUtilMath.h> #include <FLocLocation.h> @@ -30,7 +31,7 @@ #include "FLoc_RegionInfo.h" using namespace Tizen::Base::Utility; - +using namespace Tizen::Base; namespace Tizen { namespace Locations { @@ -70,4 +71,30 @@ _MathUtils::CalculateOverlapRegion(const _RegionInfo& region, const Location& lo return overlapArea; } +double +_MathUtils::GetShortestDistance(const Location& location, const Tizen::Base::Collection::IList& regionList) +{ + double minDistance = Double::GetMaxValue(); + int count = regionList.GetCount(); + + for (int i = 0; i < count; i++) + { + const _RegionInfo* pRegionInfo = static_cast<const _RegionInfo*> (regionList.GetAt(i)); + + if (pRegionInfo) + { + Coordinates regionCoordinate = pRegionInfo->GetCoordinate(); + double distance = abs(regionCoordinate.GetDistanceTo(location.GetCoordinates()) - pRegionInfo->GetRadius()); + + if (minDistance > distance) + { + minDistance = distance; + } + } + } + + SysLog(NID_LOC, "Shortest distance from location (lat: %lf and lon: %lf) to the nearest region boundary is (%lf) meters", location.GetCoordinates().GetLatitude(), location.GetCoordinates().GetLongitude(), minDistance); + + return minDistance; +} } } // Tizen::Locations |