2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FLocLocationProvider.h
20 * @brief This is the header file for the %LocationProvider class.
22 * This header file contains the declarations of the %LocationProvider class.
25 #ifndef _FLOC_LOCATION_PROVIDER_H_
26 #define _FLOC_LOCATION_PROVIDER_H_
28 #include <FBaseObject.h>
29 #include <FLocTypes.h>
31 namespace Tizen { namespace Locations
33 class LocationCriteria;
35 class ILocationProviderListener;
38 * @class LocationProvider
39 * @brief This class provides methods to get locations and enable region monitoring.
43 * @final This class is not intended for extension.
45 * The %LocationProvider class is a fundamental module that provides location-based services: location providing and region monitoring.
46 * The location provider is constructed with a location criteria and offers the services trying to satisfy it in a best-effort manner.
47 * An application gets locations by simply calling the GetLocation() method, or requesting asynchronous location updates with the
48 * StartLocationUpdatesByInterval() and StartLocationUpdatesByDistance() methods. An application can also register regions by calling the
49 * AddMonitoringRegion() method to be notified when moving into or out of regions. It gets asynchronous location updates and notifications
50 * from the region monitoring by assigning a listener, which implements the ILocationProviderListener interface, to the location provider.
52 * @see LocationCriteria
54 class _OSP_EXPORT_ LocationProvider
55 : public Tizen::Base::Object
59 * The object is not fully constructed after this constructor is called. For full construction, the Construct() method must be called right after
60 * calling this constructor.
64 LocationProvider(void);
67 * This destructor overrides Tizen::Base::Object::~Object().
71 virtual ~LocationProvider(void);
74 * Initializes this instance of %LocationProvider with the specified @c criteria and @c listener.
76 * An application chooses the desired service quality based on its scenario and constructs the location provider with the specified
77 * @c criteria. The desired accuracy for locations is a configurable property of LocationCriteria.
78 * The location provider tries to provides locations and services based on the specified @c criteria.
80 * The @c listener is notified on asynchronous location updates or region monitoring events.
84 * @return An error code
85 * @param[in] criteria The desired location criteria
86 * @param[in] listener The listener to register
87 * @exception E_SUCCESS The method is successful.
88 * @exception E_SYSTEM A system error has occurred.
90 result Construct(const LocationCriteria& criteria, ILocationProviderListener& listener);
93 * Requests the location updates service with the specific @c interval.
95 * Once the location updates have started and the location provider has fixed the current location, the location is delivered
96 * to the listener by calling the ILocationProviderListener::OnLocationUpdated() method.
97 * The location provider is trying to provide accurate locations as requested in the criteria, but locations updated by the location provider
98 * do not always fall into the requested accuracy level. It provides locations in low-grade accuracy if that is all it can offer
99 * or can not even provide locations when it hardly fixes the current location. The location provider notifies the listener whenever the accuracy
100 * level of ongoing updates are changed by calling the ILocationProviderListener::OnAccuracyChanged() method.
102 * The location updates can be paused by the location provider when the application is unable to point locations out to the user
103 * for the moment. This is possible for the following situations:
104 * - The application is not running in foreground.
105 * - The screen is off.
106 * In this case, the location provider notifies the status @c LOC_SVC_STATUS_PAUSED to the listener.
107 * It resumes the paused location updates when the application gets out of the situations.
108 * To get the location updates all the time, the application should use the KeepLocationUpdateAwake() method.
110 * The change in the service status that the location provider is providing are notified to the listener
111 * by calling the ILocationProviderListener::OnLocationUpdateStatusChanged() method.
113 * If the location updates are already started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance() methods,
114 * the location provider cancels the prior request and restarts the updates with the specified parameter.
117 * @privilege %http://tizen.org/privilege/location
119 * @return An error code
120 * @param[in] interval The update interval in seconds
121 * @exception E_SUCCESS The method is successful.
122 * @exception E_INVALID_ARG The specified @c interval is less than @c 1.
123 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
124 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
125 * @see StopLocationUpdates()
127 result StartLocationUpdatesByInterval(int interval);
130 * Requests the location updates service with the specific @c distance filter.
132 * Once the location updates have started, the initial location is delivered soon after it becomes available to the listener
133 * by calling the ILocationProviderListener::OnLocationUpdated() method. Then the location provider updates subsequent locations
134 * when it changes over the specified @c distance.
136 * The location updates can be paused by the location provider when the application is unable to point locations out to the user
137 * for the moment. This is possible for the following situations:
138 * - The application is not running in foreground.
139 * - The screen is off.
140 * In this case, the location provider notifies the status @c LOC_SVC_STATUS_PAUSED to the listener.
141 * It resumes the paused location updates when the application gets out of the situations.
142 * To get the location updates all the time, the application should use the KeepLocationUpdateAwake() method.
144 * Along with the service status, the accuracy level that the location provider is currently providing
145 * is notified to the listener on changes by calling the ILocationProviderListener::OnLocationUpdateStatusChanged()
146 * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
148 * If the location updates are already started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance() methods,
149 * the location provider cancels the prior request and restarts the updates with the specified parameter.
152 * @privilege %http://tizen.org/privilege/location
154 * @return An error code
155 * @param[in] distance The distance in meters
156 * @exception E_SUCCESS The method is successful.
157 * @exception E_INVALID_ARG The specified @c distance is less than or equal to @c 0.0 or @c NaN.
158 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
159 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
160 * @see StopLocationUpdates()
162 result StartLocationUpdatesByDistance(double distance);
165 * Stops the location updates.
169 * @return An error code
170 * @exception E_SUCCESS The method is successful.
171 * @exception E_INVALID_OPERATION The location updates has not been requested.
172 * @see StartLocationUpdatesByInterval()
173 * @see StartLocationUpdatesByDistance()
175 result StopLocationUpdates(void);
178 * Keeps the location updates awake or not.
180 * The location provider can pause the ongoing location updates when the application is unable to point locations out to the user
181 * for the moment. This is possible for the following situations:
182 * - The application is not running in foreground.
183 * - The screen is off.
185 * To get the location updates all the time, the application should use the StartLocationUpdatesByInterval() or
186 * StartLocationUpdatesByDistance() methods together with the %KeepLocationUpdateAwake() method turning the flag @c enable on.
187 * The application should be cautious about doing so since it can make the system awake
188 * during the location updates.
191 * @privilege %http://tizen.org/privilege/location and %http://tizen.org/privilege/power @n
192 * Both privileges are required.
194 * @return An error code
195 * @param[in] enable Set to @c true to keep the location updates awake, @n
197 * @exception E_SUCCESS The method is successful.
198 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
199 * @see StartLocationUpdatesByInterval()
200 * @see StartLocationUpdatesByDistance()
201 * @see StopLocationUpdates()
203 result KeepLocationUpdateAwake(bool enable);
206 * Adds a region for monitoring.
208 * A region is defined by a center point and a radius.
209 * The location provider starts the region monitoring service until all regions are removed. When it detects a movement that crosses the
210 * boundary of a registered region, it notifies the application by calling ILocationProviderListener::OnRegionEntered() or
211 * ILocationProviderListener::OnRegionLeft() with the region identifier that is returned by the %AddMonitoringRegion() method.
212 * The altitude of @c regionCenter is not considered in monitoring.
214 * Along with the service status, the accuracy level that the location provider is currently providing
215 * is notified to the listener on changes by calling the ILocationProviderListener::OnRegionMonitoringStatusChanged()
216 * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
218 * Note that, the monitoring service can sometimes makes the system awake by running costly positioning devices.
221 * @privilege %http://tizen.org/privilege/location and %http://tizen.org/privilege/power @n
222 * Both privileges are required.
224 * @return An error code
225 * @param[in] regionCenter The center coordinate of the region
226 * @param[in] radius The monitoring radius in meters
227 * @param[out] regionId The ID for the registered region
228 * @exception E_SUCCESS The method is successful.
229 * @exception E_INVALID_ARG The @c radius is not in the supported monitoring raidus range, which currently is [50, 100000] meters, @n
230 * else the @c radius or the latitude or the longitude of @c regionCenter is @c NaN
231 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
232 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
233 * @see RemoveMonitoringRegion()
234 * @see RemoveAllMonitoringRegions()
236 result AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId);
239 * Removes the monitoring region.
243 * @return An error code
244 * @param[in] regionId The region ID to remove
245 * @exception E_SUCCESS The method is successful.
246 * @exception E_INVALID_ARG The specified @c regionId is invalid.
247 * @see AddMonitoringRegion()
249 result RemoveMonitoringRegion(RegionId regionId);
252 * Removes all regions that the location provider monitors.
256 * @see AddMonitoringRegion()
258 void RemoveAllMonitoringRegions(void);
261 * Gets the current service status of the location updates.
263 * The location updates service is started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance()
264 * method. If an application has not made valid requests for the service, the %GetLocationUpdateStatus() method returns @c LOC_SVC_STATUS_IDLE.
265 * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnLocationUpdateStatusChanged() listener method.
268 * @return The current service status of the location updates
270 LocationServiceStatus GetLocationUpdateStatus(void) const;
273 * Gets the current service status of the region monitoring.
275 * The region monitoring service is started by calling the AddMonitoringRegion() method.
276 * If an application has not made valid requests for the service, the %GetRegionMonitoringStatus() method returns @c LOC_SVC_STATUS_IDLE.
277 * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnRegionMonitoringStatusChanged() listener method.
280 * @return The current status of the region monitoring service
282 LocationServiceStatus GetRegionMonitoringStatus(void) const;
285 * Gets the accuracy level that the location provider is currently providing.
287 * If an application has not made valid requests for location updates and region monitoring, the %GetCurrentAccuracy() method
288 * returns @c LOC_ACCURACY_INVALID.
289 * Otherwise, it returns the accuracy level last notified by the ILocationProviderListener::OnAccuracyChanged() listener method.
292 * @return The current location accuracy
294 LocationAccuracy GetCurrentAccuracy(void) const;
297 * Gets a current location.
299 * An application can simply get the current location with the %GetLocation() method.
301 * The location provider runs and waits for positioning systems to fix the current location as requested in the criteria.
302 * If it is not fixed in some time, this method call is aborted and returns a location in low-grade accuracy or even
303 * an invalid location with an @c E_LOCATION_UNAVAILABLE error.
306 * @privilege %http://tizen.org/privilege/location
308 * @return The current location
309 * @param[in] criteria The desired location criteria
310 * @exception E_SUCCESS The method is successful.
311 * @exception E_LOCATION_UNAVAILABLE The location provider fails to fix the current location.
312 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
313 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
314 * @exception E_SYSTEM A system error has occurred.
315 * @remarks This method call takes time as the location provider runs and waits for positioning system.
316 * If the method is called from the application's main thread, it makes the application unresponsive until it returns.
317 * If an application wants to be responsive, especially within the user interaction, it should use this method
318 * in a separated thread using Tizen::Base::Runtime::Thread class,
319 * rather than in the application's main thread which handles the ui events.
320 * @remarks The specific error code can be accessed using the GetLastResult() method.
322 static Location GetLocation(const LocationCriteria& criteria);
325 * Gets the last known location.
327 * The %GetLastKnownLocation() method returns the last location the system keeps.
328 * It is always a good idea to prefer using this method than requesting current locations
329 * since using the last location preserves the location provider from running costly positioning systems.
332 * @privilege %http://tizen.org/privilege/location
334 * @return The last location
335 * @exception E_SUCCESS The method is successful.
336 * @exception E_LOCATION_UNAVAILABLE The last location is unavailable.
337 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
338 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
339 * @remarks The specific error code can be accessed using the GetLastResult() method.
341 static Location GetLastKnownLocation(void);
345 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
347 LocationProvider(const LocationProvider& rhs);
350 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
352 LocationProvider& operator =(const LocationProvider& rhs);
355 class _LocationProviderImpl* __pImpl;
356 friend class _LocationProviderImpl;
357 }; //LocationProvider
358 }} // Tizen::Locations
359 #endif // _FLOC_LOCATION_PROVIDER_H_