Geo-fencing optimization
[platform/framework/native/locations.git] / src / FLoc_LocationManager.cpp
index 6c1002d..394590e 100644 (file)
@@ -32,6 +32,7 @@
 #include <FBaseRtMutex.h>
 #include <FBaseRtTimer.h>
 #include <FBaseRtMonitor.h>
+#include <FBaseRtWaitingLoop.h>
 #include <FBaseSysLog.h>
 #include <FLocCoordinates.h>
 #include <FSysSystemTime.h>
@@ -60,15 +61,8 @@ _LocationManager::_LocationManager(void)
        , __locMethodRequested(LOC_METHOD_REQUESTED_NONE)
        , __locationMgrState(LOC_MGR_STATE_IDLE)
        , __minRequestedAccuracy(LOC_ACCURACY_INVALID)
-       , __nativeGPSServiceState(LOCATIONS_SERVICE_DISABLED)
-       , __nativeWPSServiceState(LOCATIONS_SERVICE_DISABLED)
-       , __nativeCPSServiceState(LOCATIONS_SERVICE_DISABLED)
        , __timerInterval(0)
        , __timerTicks(0)
-       , __gpsHandler(null)
-       , __wpsHandler(null)
-       , __cpsHandler(null)
-       , __pCurrentLocation(null)
        , __pLocRequestInfoList(null)
        , __pSyncLocRequestInfoList(null)
        , __pLocUpdateTimer(null)
@@ -83,8 +77,6 @@ result
 _LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval, _ILocationManagerListener* pListener, RequestId& reqId)
 {
        static RequestId nextLocRequestId = 1;
-
-       result r = E_SUCCESS;
        const int ARRAY_LIST_CAPACITY = 1;
 
        std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
@@ -93,9 +85,8 @@ _LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval,
        std::unique_ptr< _LocationRequestInfo > pLocRequestInfo(new (std::nothrow) _LocationRequestInfo(accuracy, interval, pListener, nextLocRequestId));
        SysTryReturn(NID_LOC, pLocRequestInfo, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+       result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
        SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
-
        r = pArgList->Add(*pLocRequestInfo);
        SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating", GetErrorMessage(r));
 
@@ -110,7 +101,6 @@ _LocationManager::StartLocationUpdates(LocationAccuracy accuracy, int interval,
        pArgList.release();
 
        SysLog(NID_LOC, "Request ID (%ld) is assigned for the location request with accuracy (%d) and interval (%d).", reqId, accuracy, interval);
-
        return E_SUCCESS;
 }
 
@@ -118,8 +108,6 @@ result
 _LocationManager::StopLocationUpdates(RequestId reqId)
 {
        SysLog(NID_LOC, "Location update stop requested for request ID (%d).", reqId);
-
-       result r = E_SUCCESS;
        const int ARRAY_LIST_CAPACITY = 1;
 
        std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
@@ -128,9 +116,8 @@ _LocationManager::StopLocationUpdates(RequestId reqId)
        std::unique_ptr< Integer > pReqId(new (std::nothrow) Integer(static_cast< int >(reqId)));
        SysTryReturn(NID_LOC, pReqId, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
-       r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+       result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
        SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
-
        r = pArgList->Add(*pReqId);
        SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
 
@@ -140,7 +127,40 @@ _LocationManager::StopLocationUpdates(RequestId reqId)
        SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
 
        pArgList.release();
+       return E_SUCCESS;
+}
+
+result
+_LocationManager::ChangeUpdateInterval(RequestId reqId, int interval)
+{
+       SysLog(NID_LOC, "Interval update requested for request ID (%d).", reqId);
+       const int ARRAY_LIST_CAPACITY = 2;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_LOC, pArgList, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       result r = pArgList->Construct(ARRAY_LIST_CAPACITY);
+       SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
 
+       std::unique_ptr< Integer > pReqId(new (std::nothrow) Integer(static_cast< int >(reqId)));
+       SysTryReturn(NID_LOC, pReqId, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = pArgList->Add(*pReqId);
+       SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+
+       pReqId.release();
+
+       std::unique_ptr< Integer > pInterval(new (std::nothrow) Integer(interval));
+       SysTryReturn(NID_LOC, pInterval, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       r = pArgList->Add(*pInterval);
+       SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
+
+       pInterval.release();
+
+       r = SendUserEvent(REQ_ID_UPDATE_INTERVAL, pArgList.get());
+       SysTryReturn(NID_LOC, r == E_SUCCESS, r, r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
+
+       pArgList.release();
        return E_SUCCESS;
 }
 
@@ -155,13 +175,11 @@ _LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
 
        std::unique_ptr< _SyncLocationRequestInfo > pSyncLocationRequestInfo(new (std::nothrow) _SyncLocationRequestInfo(pLocationMonitor, reqId));
        std::unique_ptr< Tizen::Base::Collection::ArrayList, Tizen::Base::Collection::AllElementsDeleter > pArgList(new (std::nothrow) ArrayList());
-
        SysTryCatch(NID_LOC, pSyncLocationRequestInfo != null && pArgList != null, , E_OUT_OF_MEMORY,
                                "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        r = pArgList->Construct(ARRAY_LIST_CAPACITY);
        SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Array Construct failed. Propogating.", GetErrorMessage(r));
-
        r = pArgList->Add(*pSyncLocationRequestInfo.get());
        SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Arraylist addition of an object failed. Propogating.", GetErrorMessage(r));
 
@@ -171,7 +189,6 @@ _LocationManager::RegisterLocationMonitor(_LocationMonitor* pLocationMonitor)
        SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to send the user event. Propagating.", GetErrorMessage(r));
 
        pArgList.release();
-
        return E_SUCCESS;
 
 CATCH:
@@ -183,7 +200,6 @@ Location
 _LocationManager::GetLastKnownLocation(void)
 {
        Location location = _LocationImpl::GetLocationInstance();
-
        Monitor synchronizer;
        result r = synchronizer.Construct();
        SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
@@ -194,28 +210,28 @@ _LocationManager::GetLastKnownLocation(void)
        SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
 
        r = pArgList->Add(location);
-       SysTryReturn(NID_LOC, r == E_SUCCESS, location, r, "[%s] Propogating.", GetErrorMessage(r));
+       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
        r = pArgList->Add(synchronizer);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false), r, "[%s] Propogating", GetErrorMessage(r));
+       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
 
        r = synchronizer.Enter();
-       SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false), r, "[%s] Propogating", GetErrorMessage(r));
+       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
 
        r = SendUserEvent(REQ_ID_GET_LAST_LOCATION, pArgList.get());
-       SysTryCatch(NID_LOC, r == E_SUCCESS, pArgList->RemoveAll(false); synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
+       SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
        pArgList.release();
 
-       SysLog(NID_LOC, "Wait the location manager to get the last location.");
+       SysLog(NID_LOC, "Wait till location manager gets the last location.");
        r = synchronizer.Wait();
        SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
        synchronizer.Exit();
-
        SysLog(NID_LOC, "Last location(validity: %x, method: %ls) retrieved.", 
                location.IsValid(), location.GetExtraInfo(L"location_method").GetPointer());
 
        return location;
 
 CATCH:
+       pArgList->RemoveAll(false);
        return location;
 }
 
@@ -248,43 +264,6 @@ _LocationManager::GetAccuracyLevel(double horAcc) const
        }
 }
 
-bool
-_LocationManager::IsAppEnabled(void)
-{
-       Boolean enable(false);
-       Monitor synchronizer;
-       result r = synchronizer.Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
-
-       std::unique_ptr< Tizen::Base::Collection::ArrayList > pArgList(new (std::nothrow) ArrayList());
-       SysTryReturn(NID_LOC, pArgList, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-       r = pArgList->Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, r, "[%s] Propogating.", GetErrorMessage(r));
-
-       r = pArgList->Add(enable);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-       r = pArgList->Add(synchronizer);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-
-       r = synchronizer.Enter();
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Propogating", GetErrorMessage(r));
-
-       r = SendUserEvent(REQ_ID_GET_APP_ACCESSIBILITY, pArgList.get());
-       SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
-       pArgList.release();
-
-       SysLog(NID_LOC, "Wait the location manager to check the app is allowed to use location.");
-       r = synchronizer.Wait();
-       SysTryCatch(NID_LOC, r == E_SUCCESS, synchronizer.Exit(), r, "[%s] Propogating", GetErrorMessage(r));
-       SysLog(NID_LOC, "Application setting state is '%ls'.", enable.ToString().GetPointer());
-       synchronizer.Exit();
-
-       return enable.ToBool();
-
-CATCH:
-       return false;
-}
-
 _LocationManager*
 _LocationManager::GetInstance(void)
 {
@@ -300,7 +279,6 @@ _LocationManager::GetInstance(void)
                        onceBlock = PTHREAD_ONCE_INIT;
                }
        }
-
        return __pUniqueInstance;
 }
 
@@ -317,7 +295,6 @@ _LocationManager::AddToLocRequestInfoList(const _LocationRequestInfo* pLocReques
                result r = _PowerManagerImpl::PowerControl(1, 1);
                SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Failed to keep the CPU in awake state.", GetErrorMessage(r));
        }
-
        SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
        RestartLocationUpdates();
        RestartUpdateTimer();
@@ -327,7 +304,6 @@ void
 _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
 {
        const int LIST_COUNT_ZERO = 0;
-
        int count = __pLocRequestInfoList->GetCount();
 
        for (int i = 0; i < count; i++)
@@ -339,17 +315,14 @@ _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
                        break;
                }
        }
-
        SysLog(NID_LOC, "Total count of request info is (%d).", __pLocRequestInfoList->GetCount());
-
        if (__pLocRequestInfoList->GetCount() == LIST_COUNT_ZERO)
        {
                _PowerManagerImpl::PowerControl(1, 0);
 
                __pLocUpdateTimer->Cancel();
-               location_manager_stop(__gpsHandler);
-               location_manager_stop(__wpsHandler);
-               location_manager_stop(__cpsHandler);
+               location_manager_stop(__gpsHandler.handle);
+               location_manager_stop(__wpsHandler.handle);
 
                Reset();
        }
@@ -363,14 +336,35 @@ _LocationManager::RemoveFromLocRequestInfoList(RequestId reqId)
 void
 _LocationManager::AddToSyncLocationRequestInfoList(_SyncLocationRequestInfo& syncLocRequestInfo)
 {
-       result r = E_SUCCESS;
-
-       r = syncLocRequestInfo.StartTimer(*this);
-       SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to start the sync timer.", GetErrorMessage(r));
+       static bool hasRetrievalStarted = false;
 
-       r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
+       result r = __pSyncLocRequestInfoList->Add(syncLocRequestInfo);
        SysTryCatch(NID_LOC, r == E_SUCCESS, , r, "[%s] Failed to add the sync request into the list.", GetErrorMessage(r));
 
+       if (hasRetrievalStarted == true)
+       {
+               SysLog(NID_LOC, "The retrieval under process.");
+               return;
+       }
+       while (__pSyncLocRequestInfoList->GetCount() != 0)
+       {
+               hasRetrievalStarted = true;
+               const int WAIT_TIME = 1000;
+               WaitingLoop::GetInstance()->Wait(WAIT_TIME);
+
+               int count = __pSyncLocRequestInfoList->GetCount();
+               for (int i = 0; i < count; i++)
+               {
+                       _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
+                       if (pSyncLocRequestInfo != null)
+                       {
+                               SysLog(NID_LOC, "Handle the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
+
+                               HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
+                       }
+               }
+       }
+       hasRetrievalStarted = false;
        return;
 
 CATCH:
@@ -402,37 +396,53 @@ _LocationManager::RestartLocationUpdates(void)
                        isAccuracyChanged = true;
                }
        }
-
        if (!isAccuracyChanged)
        {
                return;
        }
-
        SysLog(NID_LOC, "Location updates are restarted and new minimum requested Accuracy is (%d).", __minRequestedAccuracy);
 
-       __pLocUpdateTimer->Cancel();
+       switch (__locMethodRequested)
+       {
+       case LOC_METHOD_REQUESTED_NONE:
+       {
+               SysLog(NID_LOC, "None of the methods running. Start all");
 
-       location_manager_stop(__gpsHandler);
-       location_manager_stop(__wpsHandler);
-       location_manager_stop(__cpsHandler);
+               result = location_manager_start(__gpsHandler.handle);
+               SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+
+               result = location_manager_start(__wpsHandler.handle);
+               SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+       }
+       break;
 
-       __nativeGPSServiceState = LOCATIONS_SERVICE_DISABLED;
-       __nativeWPSServiceState = LOCATIONS_SERVICE_DISABLED;
-       __nativeCPSServiceState = LOCATIONS_SERVICE_DISABLED;
+       case LOC_METHOD_REQUESTED_GPS:
+       {
+               SysLog(NID_LOC, "GPS Running. Start WPS.");
 
+               result = location_manager_start(__wpsHandler.handle);
+               SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+       }
+       break;
 
-       result = location_manager_start(__gpsHandler);
-       SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+       case LOC_METHOD_REQUESTED_WPS:
+       {
+               SysLog(NID_LOC, "WPS Running. Start GPS.");
 
-       result = location_manager_start(__wpsHandler);
-       SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for WPS.");
+               result = location_manager_start(__gpsHandler.handle);
+               SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for GPS.");
+       }
+       break;
 
-       result = location_manager_start(__cpsHandler);
-       SysTryLog(NID_LOC, result == 0, "Failed to start the location updates for CPS.");
+       case LOC_METHOD_REQUESTED_ALL:
+       {
+               SysLog(NID_LOC, "All the providers are already started.");
+       }
+       break;
+       }
 
        __locationMgrState = LOC_MGR_STATE_FAST_SENSING;
        __locMethodRequested = LOC_METHOD_REQUESTED_ALL;
-
 }
 
 void
@@ -440,19 +450,18 @@ _LocationManager::RestartUpdateTimer(void)
 {
        int gcd = 1;
        int count = __pLocRequestInfoList->GetCount();
-       result r = E_SUCCESS;
+
+       __pLocUpdateTimer->Cancel();
 
        if (count > 0)
        {
                const _LocationRequestInfo* pLocRequestInfo = static_cast< _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(0));
                gcd = pLocRequestInfo->GetInterval();
 
-
                for (int i = 1; i < count; i++)
                {
                        pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
                        int interval = pLocRequestInfo->GetInterval();
-
                        if (gcd != interval)
                        {
                                while (gcd != 0 && interval != 0)
@@ -463,13 +472,11 @@ _LocationManager::RestartUpdateTimer(void)
                        }
                }
        }
-
        __timerInterval = gcd;
        __timerTicks = 0;
 
        SysLog(NID_LOC, "Updated Timer interval is (%d).", __timerInterval);
-
-       r = __pLocUpdateTimer->Start(__timerInterval * 1000);
+       result r = __pLocUpdateTimer->Start(__timerInterval * 1000);
        if (IsFailed(r))
        {
                SysLog(NID_LOC, "Failed to start the Location update timer.");
@@ -523,7 +530,7 @@ _LocationManager::HandleSyncRetrievalTimerExpiry(_SyncLocationRequestInfo& syncL
        }
 
        SysLog(NID_LOC, "Wait for next location(Tick: %d).", syncLocRequestInfo.GetTickCount());
-       syncLocRequestInfo.StartTimer(*this);
+       syncLocRequestInfo.IncrementTickCount();
        return;
 
 NOTIFY:
@@ -532,9 +539,9 @@ NOTIFY:
 }
 
 result
-_LocationManager::SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod)
+_LocationManager::SetLocationInformation(double latitude, double longitude, double altitude, time_t timestamp, location_method_e locMethod, Location* pLocation)
 {
-       SysLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
+       SysSecureLog(NID_LOC, "Location Information is: Latitude (%lf), Longitude (%lf), Altitude (%lf), TimeStamp (%ld), Location method (%d)", latitude, longitude, altitude, timestamp, locMethod);
 
        int res = -1;
        LocationAccuracy requiredAcc;
@@ -552,7 +559,6 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
        time_t time_stamp = 0;
 
        RequestId requestId;
-
        Location locationData = _LocationImpl::GetLocationInstance();
        _LocationImpl* pLocDataImpl = _LocationImpl::GetInstance(locationData);
 
@@ -560,11 +566,11 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
        {
        case LOCATIONS_METHOD_GPS:
        {
-               res = location_manager_get_accuracy(__gpsHandler, &accLevel, &horAcc, &verAcc);
+               res = location_manager_get_accuracy(__gpsHandler.handle, &accLevel, &horAcc, &verAcc);
                SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
                SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
 
-               res = location_manager_get_velocity(__gpsHandler, &climb, &direction, &speed, &time_stamp);
+               res = location_manager_get_velocity(__gpsHandler.handle, &climb, &direction, &speed, &time_stamp);
                SysLog(NID_LOC, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
                SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
 
@@ -575,11 +581,11 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
 
        case LOCATIONS_METHOD_WPS:
        {
-               res = location_manager_get_accuracy(__wpsHandler, &accLevel, &horAcc, &verAcc);
+               res = location_manager_get_accuracy(__wpsHandler.handle, &accLevel, &horAcc, &verAcc);
                SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
                SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
 
-               res = location_manager_get_velocity(__wpsHandler, &climb, &direction, &speed, &time_stamp);
+               res = location_manager_get_velocity(__wpsHandler.handle, &climb, &direction, &speed, &time_stamp);
                SysTryLog(NID_LOC, res == 0, "Get Velocity: Result (%d), Climb (%lf), Direction (%lf), Speed (%lf), Time stamp (%ld)", res, climb, direction, speed, time_stamp);
 
                pLocDataImpl->SetExtraInfo(L"location_method", L"network");
@@ -587,20 +593,8 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
        }
        break;
 
-       case LOCATIONS_METHOD_CPS:
-       {
-               res = location_manager_get_accuracy(__cpsHandler, &accLevel, &horAcc, &verAcc);
-               SysLog(NID_LOC, "Get Accuracy: Result (%d), Horizontal Acc (%lf), Vertical Acc (%lf)", res, horAcc, verAcc);
-               SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM, "Invalid accuracy values from Native Location Provider.");
-
-               pLocDataImpl->SetExtraInfo(L"location_method", L"network");
-               requestId = REQ_ID_SUSTAIN_CPS;
-       }
-       break;
-
        default:
                SysTryReturn(NID_LOC, false, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The location method is not valid");
-
        }
 
        Coordinates coordinates;
@@ -612,7 +606,7 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
        pLocDataImpl->SetCourse(direction);
        pLocDataImpl->SetSpeed(speed);
        pLocDataImpl->SetValidity(true);
-       *__pCurrentLocation = locationData;
+       *pLocation = locationData;
 
        requiredAcc = __minRequestedAccuracy;
        switch (requiredAcc)
@@ -654,17 +648,16 @@ _LocationManager::SetLocationInformation(double latitude, double longitude, doub
                SysLog(NID_LOC, "State is LOC_MGR_STATE_FAST_SENSING_SETTLED and accuracy is out of range. Restart location updates.");
                SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
        }
-
        return E_SUCCESS;
 }
 
 void
 _LocationManager::SendLocationCallbacks(void)
 {
-       bool isAllowed = GetAppAccessibility();
-       SysLog(NID_LOC, "Send location(validity: %x) and accessibility(%x) through the callback.", __pCurrentLocation->IsValid(), isAllowed);
+       const Location* pBestLocation = FindBestLocation();
 
-       unique_ptr< Location > pLocation(new (std::nothrow) Location(*__pCurrentLocation));
+       SysLog(NID_LOC, "Send location(validity: %x) through the callback.", pBestLocation->IsValid());
+       unique_ptr< Location > pLocation(new (std::nothrow) Location(*pBestLocation));
        SysTryReturnVoidResult(NID_LOC, pLocation != null, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
 
        int interval = __timerTicks * __timerInterval;
@@ -673,10 +666,6 @@ _LocationManager::SendLocationCallbacks(void)
                const _LocationRequestInfo* pLocRequestInfo = static_cast< const _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
                if (interval % pLocRequestInfo->GetInterval() == 0 && pLocRequestInfo->GetListener() != null)
                {
-                       if (!isAllowed)
-                       {
-                               _LocationImpl::GetInstance(*pLocation)->TurnOnDeniedFlag();
-                       }
                        pLocRequestInfo->GetListener()->OnLocationUpdated(pLocRequestInfo->GetRequestId(), *pLocation.get());
                }
        }
@@ -690,9 +679,6 @@ _LocationManager::Reset(void)
        __minRequestedAccuracy = LOC_ACCURACY_INVALID;
        __timerInterval = 0;
        __timerTicks = 0;
-       __nativeGPSServiceState = LOCATIONS_SERVICE_DISABLED;
-       __nativeWPSServiceState = LOCATIONS_SERVICE_DISABLED;
-       __nativeCPSServiceState = LOCATIONS_SERVICE_DISABLED;
 }
 
 result
@@ -701,96 +687,362 @@ _LocationManager::Construct()
        return EventDrivenThread::Construct();
 }
 
-bool
-_LocationManager::OnStart(void)
+Location
+_LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
 {
-       int res = -1;
-       result r = E_SUCCESS;
-
-       unique_ptr< Mutex > pMutex(new (std::nothrow) Mutex());
-       SysTryReturn(NID_LOC, pMutex != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pMutex->Create();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the mutex.");
-
-       std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList());
-       SysTryReturn(NID_LOC, pLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
-       r = pLocInfoRequestList->Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Location Request list.");
-
-       std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList());
-       SysTryReturn(NID_LOC, pSyncLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       String locationMethod;
+       location_manager_h nativeHandle = null;
+       switch (nativeLocMethod)
+       {
+       case LOCATIONS_METHOD_GPS:
+       {
+               nativeHandle = __gpsHandler.handle;
+               locationMethod = L"gps";
+       }
+       break;
 
-       r = pSyncLocInfoRequestList->Construct();
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+       case LOCATIONS_METHOD_WPS:
+       {
+               nativeHandle = __wpsHandler.handle;
+               locationMethod = L"network";
+       }
+       break;
 
-       unique_ptr< Tizen::Locations::Location > pLocation(_LocationImpl::GetLocationInstanceN());
-       SysTryReturn(NID_LOC, pLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       default:
+               break;
+       }
+       SysLog(NID_LOC, "Last location requested(method: %x, handle: %x).", nativeLocMethod, nativeHandle);
 
-       std::unique_ptr< Tizen::Base::Runtime::Timer > pLocUpdateTimer(new (std::nothrow) Timer());
-       r = pLocUpdateTimer->Construct(*this);
-       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location timer.");
+       Location location = _LocationImpl::GetLocationInstance();
+       if (nativeHandle != null)
+       {
+               _LocationImpl* pLocationImpl = _LocationImpl::GetInstance(location);
 
-       res = location_manager_create(LOCATIONS_METHOD_GPS, &__gpsHandler);
-       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM, "[E_SYSTEM] Failed to create Native GPS Location provider.");
+               double altitude = Tizen::Locations::NaN;
+               double latitude = Tizen::Locations::NaN;
+               double longitude = Tizen::Locations::NaN;
+               time_t timestampPosition = 0;
 
-       res = location_manager_set_service_state_changed_cb(__gpsHandler, GpsServiceUpdateCallback, this);
-       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native GPS Location provider.");
+               int res = location_manager_get_last_position(nativeHandle, &altitude, &latitude, &longitude, &timestampPosition);
+               SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to fetch last position from nativeHandle(%x).", nativeHandle);
+               SysSecureLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %ld",
+                       latitude, longitude, altitude, timestampPosition);
 
-       res = location_manager_create(LOCATIONS_METHOD_WPS, &__wpsHandler);
-       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native WPS Location provider.");
+               Coordinates coord;
+               coord.Set(latitude, longitude, altitude);
+               pLocationImpl->SetCoordinates(coord);
 
-       res = location_manager_set_service_state_changed_cb(__wpsHandler, WpsServiceUpdateCallback, this);
-       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native WPS Location provider.");
+               double horAcc = Tizen::Locations::NaN;
+               double verAcc = Tizen::Locations::NaN;
+               location_accuracy_level_e level;
+               res = location_manager_get_last_accuracy(nativeHandle, &level, &horAcc, &verAcc);
+               if (res == 0)
+               {
+                       SysLog(NID_LOC, "Last accuracy(horAcc: %lf, vAcc: %lf, level: %x)", horAcc, verAcc, level);
+                       pLocationImpl->SetHorizontalAccuracy(horAcc);
+                       pLocationImpl->SetVerticalAccuracy(verAcc);
+               }
 
-       res = location_manager_create(LOCATIONS_METHOD_CPS, &__cpsHandler);
-       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native CPS Location provider.");
+               double climb = Tizen::Locations::NaN;
+               double direction = Tizen::Locations::NaN;
+               double speed = Tizen::Locations::NaN;
+               time_t timestampVelocity = 0;
+               res = location_manager_get_last_velocity(nativeHandle, &climb, &direction, &speed, &timestampVelocity);
+               if (res == 0)
+               {
+                       SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %lf, timestamp: %ld)",
+                               climb, direction, speed, timestampVelocity);
+                       pLocationImpl->SetCourse(direction);
+                       pLocationImpl->SetSpeed(speed);
+               }
 
-       res = location_manager_set_service_state_changed_cb(__cpsHandler, CpsServiceUpdateCallback, this);
-       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native CPS Location provider.");
+               if (nativeLocMethod == LOCATIONS_METHOD_GPS)
+               {
+                       int satUsedCount = 0;
+                       int satViewCount = 0;
+                       time_t timestampSatellite = 0;
+                       String satInfo = L"";
+                       res = gps_status_get_last_satellite(nativeHandle, &satUsedCount, &satViewCount, &timestampSatellite);
+                       if (res == 0)
+                       {
+                               long timeDiff = abs(timestampPosition - timestampSatellite);
+                               res = gps_status_foreach_last_satellites_in_view(nativeHandle, SatelliteInfoUpdated, &satInfo);
+                               SysLog(NID_LOC, "Last satellite(foreachResult: %d, inUse: %d, inView: %d, timestamp: %ld, timeDiff: %ld)",
+                                       res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
 
-       __pLocRequestInfoList = std::move(pLocInfoRequestList);
-       __pSyncLocRequestInfoList = std::move(pSyncLocInfoRequestList);
-       __pLocUpdateTimer = std::move(pLocUpdateTimer);
-       __pCurrentLocation = std::move(pLocation);
+                               satInfo.Trim();
+                               SysLog(NID_LOC, "Last satellite(info: %ls)", satInfo.GetPointer());
+                               pLocationImpl->SetExtraInfo(L"satellite", satInfo);
+                       }
+               }
+               pLocationImpl->SetTimestamp(((long long)timestampPosition) * 1000); // in milliseconds
+               pLocationImpl->SetValidity(true);
+               pLocationImpl->SetExtraInfo(L"location_method", locationMethod);
+       }
 
-       return true;
+       ClearLastResult();
+       return location;
 
 CATCH:
-       if (__gpsHandler)
-       {
-               location_manager_destroy(__gpsHandler);
-       }
+       return location;
+}
 
-       if (__wpsHandler)
-       {
-               location_manager_destroy(__wpsHandler);
-       }
+Location
+_LocationManager::GetRecentLocationAvailable(void)
+{
+       long long gpsTimestamp = 0;
+       long long wpsTimestamp = 0;
 
-       if (__cpsHandler)
+       Location lastGpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_GPS);
+       if (lastGpsLocation.IsValid())
        {
-               location_manager_destroy(__cpsHandler);
+               gpsTimestamp = _LocationImpl::GetInstance(lastGpsLocation)->GetTimestampInMs();
        }
-       return false;
-}
 
-void
-_LocationManager::OnStop(void)
-{
-       if (__gpsHandler)
+       Location lastWpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_WPS);
+       if (lastWpsLocation.IsValid())
        {
-               location_manager_destroy(__gpsHandler);
+               wpsTimestamp = _LocationImpl::GetInstance(lastWpsLocation)->GetTimestampInMs();
        }
 
-       if (__wpsHandler)
+       SysLog(NID_LOC, "Compare timestamp(gps: %lld, wps: %lld) for recent location.", gpsTimestamp, wpsTimestamp);
+       if (gpsTimestamp >= wpsTimestamp)
        {
-               location_manager_destroy(__wpsHandler);
+               return lastGpsLocation;
        }
-
-       if (__cpsHandler)
+       else
        {
-               location_manager_destroy(__cpsHandler);
+               return lastWpsLocation;
+       }
+}
+
+void 
+_LocationManager::UpdateLocRequestInfoList(RequestId reqId, int interval)
+{
+       int count = __pLocRequestInfoList->GetCount();
+
+       for (int i = 0; i < count; i++)
+       {
+               _LocationRequestInfo* pLocRequestInfo = static_cast< _LocationRequestInfo* >(__pLocRequestInfoList->GetAt(i));
+               if (reqId == pLocRequestInfo->GetRequestId())
+               {
+                       pLocRequestInfo->SetInterval(interval);
+                       RestartUpdateTimer();
+                       break;
+               }
+       }
+}
+
+const Location*
+_LocationManager::FindBestLocation(void)
+{
+       switch (__locMethodRequested)
+       {
+       case LOC_METHOD_REQUESTED_GPS:
+       {
+               SysLog(NID_LOC, "GPS location provider running.");
+               return __gpsHandler.pLocation.get();
+       }
+       break;
+
+       case LOC_METHOD_REQUESTED_WPS:
+       {
+               SysLog(NID_LOC, "WPS location provider running.");
+               return __wpsHandler.pLocation.get();
+       }
+       break;
+
+       case LOC_METHOD_REQUESTED_ALL:
+       {
+               SysLog(NID_LOC, "All the methods are running. Get the best location among all the providers.");
+               long long gpsTimestamp = 0;
+               long long wpsTimestamp = 0;
+
+               if (__gpsHandler.pLocation->IsValid())
+               {
+                       gpsTimestamp = _LocationImpl::GetInstance(*__gpsHandler.pLocation)->GetTimestampInMs();
+               }
+               if (__wpsHandler.pLocation->IsValid())
+               {
+                       wpsTimestamp = _LocationImpl::GetInstance(*__wpsHandler.pLocation)->GetTimestampInMs();
+               }
+
+               SysLog(NID_LOC, "Compare timestamp(gps: %lld, wps: %lld) of different locations.", gpsTimestamp, wpsTimestamp);
+               if (gpsTimestamp > wpsTimestamp)
+               {
+                       SysLog(NID_LOC, "GPS time stamp is greater than WPS.");
+                       return __gpsHandler.pLocation.get();
+               }
+               else if (wpsTimestamp > gpsTimestamp)
+               {
+                       SysLog(NID_LOC, "WPS time stamp is greater than GPS.");
+                       return __wpsHandler.pLocation.get();
+               }
+               else if (gpsTimestamp == wpsTimestamp)
+               {
+                       if (__gpsHandler.pLocation->GetHorizontalAccuracy() <= __wpsHandler.pLocation->GetHorizontalAccuracy())
+                       {
+                               SysLog(NID_LOC, "GPS time stamp is equal to WPS and GPS accuracy is better than WPS.");
+                               return __gpsHandler.pLocation.get();
+                       }
+                       else
+                       {
+                               SysLog(NID_LOC, "WPS time stamp is equal to GPS but WPS accuracy is better than GPS.");
+                               return __wpsHandler.pLocation.get();
+                       }
+               }
+       }
+       break;
+
+       case LOC_METHOD_REQUESTED_NONE:
+       // follow through
+       default:
+               SysLog(NID_LOC, "Location updates not running.");
+               return null;
+       }
+
+       SysLog(NID_LOC, "Returning null as none of the conditions are satsfied.");
+       return null;
+}
+
+result
+_LocationManager::GetLocation(location_method_e nativeLocMethod)
+{
+       const int MAX_VALID_TIME_DIFFERENCE = 2000;
+       double altitude = 0.0;
+       double latitude = 0.0;
+       double longitude = 0.0;
+       time_t timestamp;
+       int res = -1;
+       int satellitesInViewCount = 0;
+       int satellitesInUseCount = 0;
+       time_t timestampSatellite = 0;
+       String satInfo = L"";
+       long long timeDiff = 0;
+       location_manager_h nativeHandle = null;
+       Location* pLocation = null;
+
+       switch (nativeLocMethod)
+       {
+       case LOCATIONS_METHOD_GPS:
+       {
+               nativeHandle = __gpsHandler.handle;
+               pLocation = __gpsHandler.pLocation.get();
+       }
+       break;
+
+       case LOCATIONS_METHOD_WPS:
+       {
+               nativeHandle = __wpsHandler.handle;
+               pLocation = __wpsHandler.pLocation.get();
+       }
+       break;
+
+       default:
+               break;
+       }
+
+       res = location_manager_get_position(nativeHandle, &altitude, &latitude, &longitude, &timestamp);
+       SysTryReturnResult(NID_LOC, res == 0, E_SYSTEM,  "Failed to obtain the natvie location information for the method (%x)", nativeLocMethod);
+
+       if (res == 0)
+       {
+               result r = SetLocationInformation(latitude, longitude, altitude, timestamp, nativeLocMethod, pLocation);
+               if (r != E_SUCCESS)
+               {
+                       SysLog(NID_LOC, "Failed to set the location information");
+               }
+
+               if (nativeLocMethod == LOCATIONS_METHOD_GPS)
+               {
+                       res = gps_status_get_satellite(__gpsHandler.handle, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
+
+                       timeDiff = abs(timestamp - timestampSatellite);
+                       timeDiff = timeDiff * 1000;
+                       SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
+                                  res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
+                       if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
+                       {
+                               res = gps_status_foreach_satellites_in_view(__gpsHandler.handle, SatelliteInfoUpdated, &satInfo);
+                       }
+                       satInfo.Trim();
+                       SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
+                       _LocationImpl::GetInstance(*__gpsHandler.pLocation.get())->SetExtraInfo(L"satellite", satInfo);
+               }
+       }
+
+       return E_SUCCESS;
+}
+
+bool
+_LocationManager::OnStart(void)
+{
+       int res = -1;
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pLocInfoRequestList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_LOC, pLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       result r = pLocInfoRequestList->Construct();
+       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Location Request list.");
+
+       std::unique_ptr< Tizen::Base::Collection::ArrayList, AllElementsDeleter > pSyncLocInfoRequestList(new (std::nothrow) ArrayList());
+       SysTryReturn(NID_LOC, pSyncLocInfoRequestList != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       r = pSyncLocInfoRequestList->Construct();
+       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the Sync Location Request list.");
+
+       unique_ptr< Tizen::Locations::Location > pGpsLocation(_LocationImpl::GetLocationInstanceN());
+       SysTryReturn(NID_LOC, pGpsLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+       unique_ptr< Tizen::Locations::Location > pWpsLocation(_LocationImpl::GetLocationInstanceN());
+       SysTryReturn(NID_LOC, pWpsLocation != null, false, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
+
+       std::unique_ptr< Tizen::Base::Runtime::Timer > pLocUpdateTimer(new (std::nothrow) Timer());
+       r = pLocUpdateTimer->Construct(*this);
+       SysTryReturn(NID_LOC, r == E_SUCCESS, false, E_SYSTEM, "[E_SYSTEM] Failed to construct the location timer.");
+
+       res = location_manager_create(LOCATIONS_METHOD_GPS, &__gpsHandler.handle);
+       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM, "[E_SYSTEM] Failed to create Native GPS Location provider.");
+       res = location_manager_set_service_state_changed_cb(__gpsHandler.handle, GpsServiceUpdateCallback, this);
+       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native GPS Location provider.");
+
+       res = location_manager_create(LOCATIONS_METHOD_WPS, &__wpsHandler.handle);
+       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to create Native WPS Location provider.");
+       res = location_manager_set_service_state_changed_cb(__wpsHandler.handle, WpsServiceUpdateCallback, this);
+       SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to register service callback for Native WPS Location provider.");
+
+       __pLocRequestInfoList = std::move(pLocInfoRequestList);
+       __pSyncLocRequestInfoList = std::move(pSyncLocInfoRequestList);
+       __pLocUpdateTimer = std::move(pLocUpdateTimer);
+       __gpsHandler.pLocation= std::move(pGpsLocation);
+       __wpsHandler.pLocation= std::move(pWpsLocation);
+
+       __waitLoopListener.SetValue(true);
+       SysLog(NID_LOC, "All the resources for location manager successfully created.");
+       return true;
+
+CATCH:
+       if (__gpsHandler.handle)
+       {
+               location_manager_destroy(__gpsHandler.handle);
+       }
+
+       if (__wpsHandler.handle)
+       {
+               location_manager_destroy(__wpsHandler.handle);
+       }
+       return false;
+}
+
+void
+_LocationManager::OnStop(void)
+{
+       __waitLoopListener.SetValue(false);
+
+       if (__gpsHandler.handle)
+       {
+               location_manager_destroy(__gpsHandler.handle);
+       }
+       if (__wpsHandler.handle)
+       {
+               location_manager_destroy(__wpsHandler.handle);
        }
 }
 
@@ -837,8 +1089,7 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
        case REQ_ID_SUSTAIN_GPS:
        {
                SysLog(NID_LOC, "REQ_ID_SUSTAIN_GPS.");
-               location_manager_stop(__wpsHandler);
-               location_manager_stop(__cpsHandler);
+               location_manager_stop(__wpsHandler.handle);
                __locMethodRequested = LOC_METHOD_REQUESTED_GPS;
        }
        break;
@@ -846,21 +1097,11 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
        case REQ_ID_SUSTAIN_WPS:
        {
                SysLog(NID_LOC, "REQ_ID_SUSTAIN_WPS.");
-               location_manager_stop(__gpsHandler);
-               location_manager_stop(__cpsHandler);
+               location_manager_stop(__gpsHandler.handle);
                __locMethodRequested = LOC_METHOD_REQUESTED_WPS;
        }
        break;
 
-       case REQ_ID_SUSTAIN_CPS:
-       {
-               SysLog(NID_LOC, "REQ_ID_SUSTAIN_CPS.");
-               location_manager_stop(__gpsHandler);
-               location_manager_stop(__wpsHandler);
-               __locMethodRequested = LOC_METHOD_REQUESTED_CPS;
-       }
-       break;
-
        case REQ_ID_SYNC_LOC_RETRIEVAL:
        {
                SysLog(NID_LOC, "REQ_ID_SYNC_LOC_RETRIEVAL.");
@@ -871,30 +1112,6 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
                SysTryCatch(NID_LOC, pSyncLocRequestInfo, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
 
                AddToSyncLocationRequestInfoList(*pSyncLocRequestInfo);
-
-               pArgs->RemoveAt(0);
-       }
-       break;
-
-       case REQ_ID_GET_APP_ACCESSIBILITY:
-       {
-               SysLog(NID_LOC, "REQ_ID_GET_APP_ACCESSIBILITY");
-               SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
-
-               Boolean* pEnabled = static_cast< Boolean* >(pArgs->GetAt(0));
-               Monitor* pMonitor = static_cast< Monitor* >(pArgs->GetAt(1));
-               SysAssertf(pEnabled != null && pMonitor != null, "Invalid request has been made on the location manager.");
-               if (pMonitor != null)
-               {
-                       pMonitor->Enter();
-                       if (pEnabled != null)
-                       {
-                               pEnabled->value = GetAppAccessibility();
-                       }
-                       pMonitor->Notify();
-                       pMonitor->Exit();
-               }
-               pArgs->RemoveAt(1);
                pArgs->RemoveAt(0);
        }
        break;
@@ -921,6 +1138,27 @@ _LocationManager::OnUserEventReceivedN(RequestId requestId, IList* pArgs)
                pArgs->RemoveAt(0);
        }
        break;
+
+       case REQ_ID_UPDATE_INTERVAL:
+       {
+               const int ARRAY_LIST_LENGTH = 2;
+
+               SysLog(NID_LOC, "REQ_ID_UPDATE_INTERVAL");
+               SysTryReturnVoidResult(NID_LOC, pArgs, E_INVALID_ARG, "[E_INVALID_ARG] Null argument encountered. Ignored.");
+               SysTryCatch(NID_LOC, pArgs->GetCount() == ARRAY_LIST_LENGTH, pArgs->RemoveAll(true), E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+               Integer* pReqId = null;
+               pReqId = static_cast< Integer* >(pArgs->GetAt(0));
+               SysTryCatch(NID_LOC, pReqId, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+               Integer* pInterval = null;
+               pInterval = static_cast< Integer* >(pArgs->GetAt(1));
+               SysTryCatch(NID_LOC, pInterval, , E_INVALID_ARG, "[E_INVALID_ARG] Invalid argument encountered. Ignored.");
+
+               UpdateLocRequestInfoList(static_cast< long >(pReqId->ToInt()), pInterval->ToInt());
+       }
+       break;
+
        }
 
        if (pArgs)
@@ -939,165 +1177,59 @@ CATCH:
 void
 _LocationManager::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
 {
-       const int MAX_VALID_TIME_DIFFERENCE = 2000;
-
        if (__pLocUpdateTimer->Equals(timer))
        {
                __timerTicks++;
                SysLog(NID_LOC, "LocationManager update timer expired. Timer Tick value is (%d).", __timerTicks);
                result r = E_SUCCESS;
-               double altitude = 0.0;
-               double latitude = 0.0;
-               double longitude = 0.0;
-               time_t timestamp;
-
-               int res = -1;
-               int satellitesInViewCount = 0;
-               int satellitesInUseCount = 0;
-               time_t timestampSatellite = 0;
-               String satInfo = L"";
-               long long timeDiff = 0;
 
                switch (__locMethodRequested)
                {
                case LOC_METHOD_REQUESTED_GPS:
-                       res = location_manager_get_position(__gpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                       SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the GPS location information");
-
-                       if (res == 0)
-                       {
-                               r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_GPS);
-                               if (r != E_SUCCESS)
-                               {
-                                       SysLog(NID_LOC, "Failed to set the location information");
-                               }
-
-                               res = gps_status_get_satellite(__gpsHandler, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
-
-                               timeDiff = abs(timestamp - timestampSatellite);
-                               timeDiff = timeDiff * 1000;
-                               SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
-                                          res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
-                               if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
-                               {
-                                       res = gps_status_foreach_satellites_in_view(__gpsHandler, SatelliteInfoUpdated, &satInfo);
-                               }
-                               SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
-
-                               _LocationImpl::GetInstance(*__pCurrentLocation.get())->SetExtraInfo(L"satellite", satInfo);
-                       }
-                       else
+               {
+                       r = GetLocation(LOCATIONS_METHOD_GPS);
+                       SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information");
+                       if (IsFailed(r))
                        {
                                SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
-                               return;
                        }
-                       break;
+               }
+               break;
 
                case LOC_METHOD_REQUESTED_WPS:
-                       res = location_manager_get_position(__wpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                       SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the WPS location information");
-                       if (res == 0)
-                       {
-                               r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_WPS);
-                               if (r != E_SUCCESS)
-                               {
-                                       SysLog(NID_LOC, "Failed to set the location information");
-                               }
-                       }
-                       else
-                       {
-                               SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
-                               return;
-                       }
-                       break;
-
-               case LOC_METHOD_REQUESTED_CPS:
-                       res = location_manager_get_position(__cpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                       SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the CPS location information");
-                       if (res == 0)
-                       {
-                               r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_CPS);
-                               if (r != E_SUCCESS)
-                               {
-                                       SysLog(NID_LOC, "Failed to set the location information");
-                               }
-                       }
-                       else
+               {
+                       r = GetLocation(LOCATIONS_METHOD_WPS);
+                       SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information");
+                       if (IsFailed(r))
                        {
                                SendUserEvent(REQ_ID_RESTART_LOC_UPDATES, null);
-                               return;
                        }
-                       break;
+               }
+               break;
 
                case LOC_METHOD_REQUESTED_ALL:
-                       if (__nativeCPSServiceState == LOCATIONS_SERVICE_ENABLED)
-                       {
-                               res = location_manager_get_position(__cpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                               SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the CPS location information");
-                               if (res == 0)
-                               {
-                                       r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_CPS);
-                                       if (r != E_SUCCESS)
-                                       {
-                                               SysLog(NID_LOC, "Failed to set the location information");
-                                       }
-                               }
-                       }
-                       else
-                       {
-                               SysLog(NID_LOC, "CPS Location not available at the Native side.");
-                       }
-
-                       if (__nativeWPSServiceState == LOCATIONS_SERVICE_ENABLED)
+               {
+                       if (__wpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
                        {
-                               res = location_manager_get_position(__wpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                               SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the WPS location information");
-                               if (res == 0)
-                               {
-                                       r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_WPS);
-                                       if (r != E_SUCCESS)
-                                       {
-                                               SysLog(NID_LOC, "Failed to set the location information");
-                                       }
-                               }
+                               r = GetLocation(LOCATIONS_METHOD_WPS);
+                               SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the WPS location information");
                        }
                        else
                        {
                                SysLog(NID_LOC, "WPS Location not available at the Native side.");
                        }
 
-                       if (__nativeGPSServiceState == LOCATIONS_SERVICE_ENABLED)
+                       if (__gpsHandler.serviceState == LOCATIONS_SERVICE_ENABLED)
                        {
-                               res = location_manager_get_position(__gpsHandler, &altitude, &latitude, &longitude, &timestamp);
-                               SysTryLog(NID_LOC, res == 0, "[E_SYSTEM] Failed to obtain the GPS location information");
-                               if (res == 0)
-                               {
-                                       r = SetLocationInformation(latitude, longitude, altitude, timestamp, LOCATIONS_METHOD_GPS);
-                                       if (r != E_SUCCESS)
-                                       {
-                                               SysLog(NID_LOC, "Failed to set the location information");
-                                       }
-
-                                       res = gps_status_get_satellite(__gpsHandler, &satellitesInUseCount, &satellitesInViewCount, &timestampSatellite);
-
-                                       timeDiff = abs(timestamp - timestampSatellite);
-                                       timeDiff = timeDiff * 1000;
-                                       SysLog(NID_LOC, "Result (%d), Satellites in Use (%d), Satellites in View (%d), Time stamp (%ld), Time Difference (Loc and Sat) (%ld)",
-                                                  res, satellitesInUseCount, satellitesInViewCount, timestampSatellite, timeDiff);
-                                       if (res == 0 && timeDiff <= MAX_VALID_TIME_DIFFERENCE)
-                                       {
-                                               res = gps_status_foreach_satellites_in_view(__gpsHandler, SatelliteInfoUpdated, &satInfo);
-                                       }
-                                       SysLog(NID_LOC, "Result of get satellite is (%d) and satelliteInfo string representation is (%ls)", res, satInfo.GetPointer());
-
-                                       _LocationImpl::GetInstance(*__pCurrentLocation.get())->SetExtraInfo(L"satellite", satInfo);
-                               }
+                               r = GetLocation(LOCATIONS_METHOD_GPS);
+                               SysTryLog(NID_LOC, r == E_SUCCESS, "[E_SYSTEM] Failed to obtain the GPS location information");
                        }
                        else
                        {
                                SysLog(NID_LOC, "GPS Location not available at the Native side.");
                        }
-                       break;
+               }
+               break;
 
                case LOC_METHOD_REQUESTED_NONE:
                // follow through
@@ -1109,21 +1241,6 @@ _LocationManager::OnTimerExpired(Tizen::Base::Runtime::Timer& timer)
                __pLocUpdateTimer->Start(__timerInterval * 1000);
                SendLocationCallbacks();
        }
-       else
-       {
-               int count = __pSyncLocRequestInfoList->GetCount();
-               for (int i = 0; i < count; i++)
-               {
-                       _SyncLocationRequestInfo* pSyncLocRequestInfo = static_cast< _SyncLocationRequestInfo* >(__pSyncLocRequestInfoList->GetAt(i));
-                       if (pSyncLocRequestInfo != null && pSyncLocRequestInfo->Equals(timer))
-                       {
-                               SysLog(NID_LOC, "Timer expired for the sync location request with request ID (%ld)", pSyncLocRequestInfo->GetRequestId());
-
-                               HandleSyncRetrievalTimerExpiry(*pSyncLocRequestInfo);
-                               break;
-                       }
-               }
-       }
 
        return;
 }
@@ -1139,7 +1256,6 @@ _LocationManager::SatelliteInfoUpdated(unsigned int azimuth, unsigned int elevat
        }
 
        String* pSatInfo = static_cast< String* >(user_data);
-
        SysLog(NID_LOC, "GPS Position Satellite Info: SatID (%d), Used (%d), Elevation (%d), Azimuth (%d), Snr (%d).", prn, is_active, elevation, azimuth, snr);
 
        pSatInfo->Append(static_cast< int >(prn));
@@ -1167,7 +1283,7 @@ _LocationManager::GpsServiceUpdateCallback(location_service_state_e state, void*
        }
 
        _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
-       pThis->__nativeGPSServiceState = state;
+       pThis->__gpsHandler.serviceState = state;
 }
 
 void
@@ -1181,21 +1297,7 @@ _LocationManager::WpsServiceUpdateCallback(location_service_state_e state, void*
        }
 
        _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
-       pThis->__nativeWPSServiceState = state;
-}
-
-void
-_LocationManager::CpsServiceUpdateCallback(location_service_state_e state, void* user_data)
-{
-       SysLog(NID_LOC, "Updated State is (%d).", state);
-       if (user_data == null)
-       {
-               SysLog(NID_LOC, "User data is null. Return");
-               return;
-       }
-
-       _LocationManager* pThis = static_cast< _LocationManager* >(user_data);
-       pThis->__nativeCPSServiceState = state;
+       pThis->__wpsHandler.serviceState = state;
 }
 
 void
@@ -1205,15 +1307,14 @@ _LocationManager::InitLocationManager(void)
 
        unique_ptr< _LocationManager > pLocMgr(new (std::nothrow) _LocationManager());
        SysTryReturnVoidResult(NID_LOC, pLocMgr, E_OUT_OF_MEMORY, "[%s] Memory allocation failed.", GetErrorMessage(E_OUT_OF_MEMORY));
-
        result r = pLocMgr->Construct();
        SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to construct the Location Manager. Propagating.", GetErrorMessage(r));
-
        r = pLocMgr->Start();
        SysTryReturnVoidResult(NID_LOC, r == E_SUCCESS, r, "[%s] Falied to start the Location Manager. Propagating.", GetErrorMessage(r));
 
-       __pUniqueInstance = pLocMgr.release();
+       WaitingLoop::GetInstance()->Wait(*pLocMgr->GetWaitLoopListener());
 
+       __pUniqueInstance = pLocMgr.release();
        std::atexit(DestroyLocationManager);
 }
 
@@ -1223,171 +1324,4 @@ _LocationManager::DestroyLocationManager(void)
        delete __pUniqueInstance;
 }
 
-Location
-_LocationManager::GetLastKnownLocation(location_method_e nativeLocMethod)
-{
-       String locationMethod;
-       location_manager_h nativeHandle = null;
-       switch (nativeLocMethod)
-       {
-       case LOCATIONS_METHOD_GPS:
-               nativeHandle = __gpsHandler;
-               locationMethod = L"gps";
-               break;
-       case LOCATIONS_METHOD_WPS:
-               nativeHandle = __wpsHandler;
-               locationMethod = L"network";
-               break;
-       case LOCATIONS_METHOD_CPS:
-               nativeHandle = __cpsHandler;
-               locationMethod = L"network";
-               break;
-       default:
-               break;
-       }
-       SysLog(NID_LOC, "Last location requested(method: %x, handle: %x).", nativeLocMethod, nativeHandle);
-
-       Location location = _LocationImpl::GetLocationInstance();
-       if (nativeHandle != null)
-       {
-               _LocationImpl* pLocationImpl = _LocationImpl::GetInstance(location);
-
-               double altitude = Tizen::Locations::NaN;
-               double latitude = Tizen::Locations::NaN;
-               double longitude = Tizen::Locations::NaN;
-               time_t timestampPosition = 0;
-
-               int res = location_manager_get_last_position(nativeHandle, &altitude, &latitude, &longitude, &timestampPosition);
-               SysTryCatch(NID_LOC, res == 0, , E_SYSTEM, "[E_SYSTEM] Failed to fetch last position from nativeHandle(%x).", nativeHandle);
-               SysLog(NID_LOC, "Last position(latitude: %lf, longitude: %lf, altitude: %lf, timestamp: %lld",
-                       latitude, longitude, altitude, timestampPosition);
-               
-               Coordinates coord;
-               coord.Set(latitude, longitude, altitude);
-               pLocationImpl->SetCoordinates(coord);
-
-               double horAcc = Tizen::Locations::NaN;
-               double verAcc = Tizen::Locations::NaN;
-               location_accuracy_level_e level;
-               res = location_manager_get_last_accuracy(nativeHandle, &level, &horAcc, &verAcc);
-               if (res == 0)
-               {
-                       SysLog(NID_LOC, "Last accuracy(horAcc: %lf, vAcc: %lf, level: %x)", horAcc, verAcc, level);
-                       pLocationImpl->SetHorizontalAccuracy(horAcc);
-                       pLocationImpl->SetVerticalAccuracy(verAcc);
-               }
-               
-               double climb = Tizen::Locations::NaN;
-               double direction = Tizen::Locations::NaN;
-               double speed = Tizen::Locations::NaN;
-               time_t timestampVelocity = 0;
-               res = location_manager_get_last_velocity(nativeHandle, &climb, &direction, &speed, &timestampVelocity);
-               if (res == 0)
-               {
-                       SysLog(NID_LOC, "Last velocity(climb: %lf, direction: %lf, speed: %x, timestamp: %lld)",
-                               climb, direction, speed, timestampVelocity);
-                       pLocationImpl->SetCourse(direction);
-                       pLocationImpl->SetSpeed(speed);
-               }
-
-               if (nativeLocMethod == LOCATIONS_METHOD_GPS)
-               {
-                       int satUsedCount = 0;
-                       int satViewCount = 0;
-                       time_t timestampSatellite = 0;
-                       String satInfo = L"";
-                       res = gps_status_get_last_satellite(nativeHandle, &satUsedCount, &satViewCount, &timestampSatellite);
-                       if (res == 0)
-                       {
-                               long timeDiff = abs(timestampPosition - timestampSatellite);
-                               res = gps_status_foreach_last_satellites_in_view(nativeHandle, SatelliteInfoUpdated, &satInfo);
-                               SysLog(NID_LOC, "Last satellite(foreachResult: %d, inUse: %d, inView: %d, timestamp: %lld, timeDiff: %ld)",
-                                       res, satUsedCount, satViewCount, timestampSatellite, timeDiff);
-                               
-                               SysLog(NID_LOC, "Last satellite(info: %ls)", satInfo.GetPointer());
-                               pLocationImpl->SetExtraInfo(L"satellite", satInfo);
-                       }
-               }
-
-               pLocationImpl->SetTimestamp(((long long)timestampPosition) * 1000); // in milliseconds
-               pLocationImpl->SetValidity(true);
-               pLocationImpl->SetExtraInfo(L"location_method", locationMethod);
-       }
-
-       ClearLastResult();
-       return location;
-
-CATCH:
-       return location;
-}
-
-bool
-_LocationManager::GetAppAccessibility(void)
-{
-       int res = 0;
-       static bool appRegistered = false;
-       if (!appRegistered)
-       {
-               static const char COMMAND_REGISTER_APP[] = "ADD_APPLIST";
-               if (location_manager_send_command(COMMAND_REGISTER_APP) == LOCATIONS_ERROR_NONE)
-               {
-#ifdef _OSP_EMUL_
-                       static const char COMMAND_ENABLE_APP[] = "ACCESSIBILITY:1";
-                       res = location_manager_send_command(COMMAND_ENABLE_APP);
-                       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
-                                                "[%s] Failed to register the application.", GetErrorMessage(E_SYSTEM));
-#endif
-                       appRegistered = true;
-               }
-       }
-
-       location_accessibility_state_e accessState;
-       res = location_manager_get_accessibility_state(&accessState);
-       SysTryReturn(NID_LOC, res == 0, false, E_SYSTEM,
-                                "[%s] Failed to get the application location setting.", GetErrorMessage(E_SYSTEM));
-
-       return (accessState == LOCATIONS_ACCESS_STATE_ALLOWED) ? true : false;
-}
-
-Location
-_LocationManager::GetRecentLocationAvailable(void)
-{
-       long long gpsTimestamp = 0;
-       long long wpsTimestamp = 0;
-       long long cpsTimestamp = 0;
-
-       Location lastGpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_GPS);
-       if (lastGpsLocation.IsValid())
-       {
-               gpsTimestamp = _LocationImpl::GetInstance(lastGpsLocation)->GetTimestampInMs();
-       }
-
-       Location lastWpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_WPS);
-       if (lastWpsLocation.IsValid())
-       {
-               wpsTimestamp = _LocationImpl::GetInstance(lastWpsLocation)->GetTimestampInMs();
-       }
-
-       Location lastCpsLocation = GetLastKnownLocation(LOCATIONS_METHOD_CPS);
-       if (lastCpsLocation.IsValid())
-       {
-               cpsTimestamp = _LocationImpl::GetInstance(lastCpsLocation)->GetTimestampInMs();
-       }
-
-       SysLog(NID_LOC, "Compare timestamp(gps: %lld, wps: %lld, cps: %lld) for recent location.", 
-               gpsTimestamp, wpsTimestamp, cpsTimestamp);
-
-       if (gpsTimestamp >= wpsTimestamp && gpsTimestamp >= cpsTimestamp)
-       {
-               return lastGpsLocation;
-       }
-       else if (wpsTimestamp > gpsTimestamp && wpsTimestamp > cpsTimestamp)
-       {
-               return lastWpsLocation;
-       }
-       else
-       {
-               return lastCpsLocation;
-       }
-}
 }}