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.
118 * @privilege http://tizen.org/privilege/location
120 * @return An error code
121 * @param[in] interval The update interval in seconds
122 * @exception E_SUCCESS The method is successful.
123 * @exception E_INVALID_ARG The specified @c interval is less than @c 1.
124 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
125 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
126 * @see StopLocationUpdates()
128 result StartLocationUpdatesByInterval(int interval);
131 * Requests the location updates service with the specific @c distance filter.
133 * Once the location updates have started, the initial location is delivered soon after it becomes available to the listener
134 * by calling the ILocationProviderListener::OnLocationUpdated() method. Then the location provider updates subsequent locations
135 * when it changes over the specified @c distance.
137 * The location updates can be paused by the location provider when the application is unable to point locations out to the user
138 * for the moment. This is possible for the following situations:
139 * - The application is not running in foreground.
140 * - The screen is off.
141 * In this case, the location provider notifies the status @c LOC_SVC_STATUS_PAUSED to the listener.
142 * It resumes the paused location updates when the application gets out of the situations.
143 * To get the location updates all the time, the application should use the KeepLocationUpdateAwake() method.
145 * Along with the service status, the accuracy level that the location provider is currently providing
146 * is notified to the listener on changes by calling the ILocationProviderListener::OnLocationUpdateStatusChanged()
147 * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
149 * If the location updates are already started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance() methods,
150 * the location provider cancels the prior request and restarts the updates with the specified parameter.
154 * @privilege http://tizen.org/privilege/location
156 * @return An error code
157 * @param[in] distance The distance in meters
158 * @exception E_SUCCESS The method is successful.
159 * @exception E_INVALID_ARG The specified @c distance is less than or equal to @c 0.0 or @c NaN.
160 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
161 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
162 * @see StopLocationUpdates()
164 result StartLocationUpdatesByDistance(double distance);
167 * Stops the location updates.
171 * @return An error code
172 * @exception E_SUCCESS The method is successful.
173 * @exception E_INVALID_OPERATION The location updates has not been requested.
174 * @see StartLocationUpdatesByInterval()
175 * @see StartLocationUpdatesByDistance()
177 result StopLocationUpdates(void);
180 * Keeps the location updates awake or not.
182 * The location provider can pause the ongoing location updates when the application is unable to point locations out to the user
183 * for the moment. This is possible for the following situations:
184 * - The application is not running in foreground.
185 * - The screen is off.
187 * To get the location updates all the time, the application should use the StartLocationUpdatesByInterval() or
188 * StartLocationUpdatesByDistance() methods together with the %KeepLocationUpdateAwake() method turning the flag @c enable on.
189 * The application should be cautious about doing so since it can make the system awake
190 * during the location updates.
194 * @privilege http://tizen.org/privilege/location and http://tizen.org/privilege/power @n
195 * Both privileges are required.
197 * @return An error code
198 * @param[in] enable Set to @c true to keep the location updates awake, @n
200 * @exception E_SUCCESS The method is successful.
201 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
202 * @see StartLocationUpdatesByInterval()
203 * @see StartLocationUpdatesByDistance()
204 * @see StopLocationUpdates()
206 result KeepLocationUpdateAwake(bool enable);
209 * Adds a region for monitoring.
211 * A region is defined by a center point and a radius.
212 * The location provider starts the region monitoring service until all regions are removed. When it detects a movement that crosses the
213 * boundary of a registered region, it notifies the application by calling ILocationProviderListener::OnRegionEntered() or
214 * ILocationProviderListener::OnRegionLeft() with the region identifier that is returned by the %AddMonitoringRegion() method.
215 * The altitude of @c regionCenter is not considered in monitoring.
217 * Along with the service status, the accuracy level that the location provider is currently providing
218 * is notified to the listener on changes by calling the ILocationProviderListener::OnRegionMonitoringStatusChanged()
219 * and ILocationProviderListener::OnAccuracyChanged() methods respectively.
221 * Note that, the monitoring service can sometimes makes the system awake by running costly positioning devices.
225 * @privilege http://tizen.org/privilege/location and http://tizen.org/privilege/power @n
226 * Both privileges are required.
228 * @return An error code
229 * @param[in] regionCenter The center coordinate of the region
230 * @param[in] radius The monitoring radius in meters
231 * @param[out] regionId The ID for the registered region
232 * @exception E_SUCCESS The method is successful.
233 * @exception E_INVALID_ARG The @c radius is not in the supported monitoring raidus range, which currently is [50, 100000] meters, @n
234 * else the @c radius or the latitude or the longitude of @c regionCenter is @c NaN
235 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
236 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
237 * @see RemoveMonitoringRegion()
238 * @see RemoveAllMonitoringRegions()
240 result AddMonitoringRegion(const Coordinates& regionCenter, double radius, RegionId& regionId);
243 * Removes the monitoring region.
247 * @return An error code
248 * @param[in] regionId The region ID to remove
249 * @exception E_SUCCESS The method is successful.
250 * @exception E_INVALID_ARG The specified @c regionId is invalid.
251 * @see AddMonitoringRegion()
253 result RemoveMonitoringRegion(RegionId regionId);
256 * Removes all regions that the location provider monitors.
260 * @see AddMonitoringRegion()
262 void RemoveAllMonitoringRegions(void);
265 * Gets the current service status of the location updates.
267 * The location updates service is started by calling the StartLocationUpdatesByInterval() or StartLocationUpdatesByDistance()
268 * method. If an application has not made valid requests for the service, the %GetLocationUpdateStatus() method returns @c LOC_SVC_STATUS_IDLE.
269 * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnLocationUpdateStatusChanged() listener method.
272 * @return The current service status of the location updates
274 LocationServiceStatus GetLocationUpdateStatus(void) const;
277 * Gets the current service status of the region monitoring.
279 * The region monitoring service is started by calling the AddMonitoringRegion() method.
280 * If an application has not made valid requests for the service, the %GetRegionMonitoringStatus() method returns @c LOC_SVC_STATUS_IDLE.
281 * Otherwise, it returns the service status notified last by the ILocationProviderListener::OnRegionMonitoringStatusChanged() listener method.
284 * @return The current status of the region monitoring service
286 LocationServiceStatus GetRegionMonitoringStatus(void) const;
289 * Gets the accuracy level that the location provider is currently providing.
291 * If an application has not made valid requests for location updates and region monitoring, the %GetCurrentAccuracy() method
292 * returns @c LOC_ACCURACY_INVALID.
293 * Otherwise, it returns the accuracy level last notified by the ILocationProviderListener::OnAccuracyChanged() listener method.
296 * @return The current location accuracy
298 LocationAccuracy GetCurrentAccuracy(void) const;
301 * Gets a current location.
303 * An application can simply get the current location with the %GetLocation() method.
305 * The location provider runs and waits for positioning systems to fix the current location as requested in the criteria.
306 * If it is not fixed in some time, this method call is aborted and returns a location in low-grade accuracy or even
307 * an invalid location with an @c E_LOCATION_UNAVAILABLE error.
311 * @privilege http://tizen.org/privilege/location
313 * @return The current location
314 * @param[in] criteria The desired location criteria
315 * @exception E_SUCCESS The method is successful.
316 * @exception E_LOCATION_UNAVAILABLE The location provider fails to fix the current location.
317 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
318 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
319 * @exception E_SYSTEM A system error has occurred.
320 * @remarks This method call takes time as the location provider runs and waits for positioning system.
321 * @remarks The specific error code can be accessed using the GetLastResult() method.
323 static Location GetLocation(const LocationCriteria& criteria);
326 * Gets the last known location.
328 * The %GetLastKnownLocation() method returns the last location the system keeps.
329 * It is always a good idea to prefer using this method than requesting current locations
330 * since using the last location preserves the location provider from running costly positioning systems.
334 * @privilege http://tizen.org/privilege/location
336 * @return The last location
337 * @exception E_SUCCESS The method is successful.
338 * @exception E_LOCATION_UNAVAILABLE The last location is unavailable.
339 * @exception E_PRIVILEGE_DENIED The application does not have the privilege to call this method.
340 * @exception E_USER_NOT_CONSENTED The user blocks an application from using the location information.
341 * @remarks The specific error code can be accessed using the GetLastResult() method.
343 static Location GetLastKnownLocation(void);
347 // The implementation of this copy constructor is intentionally blank and declared as private to prohibit copying of objects.
349 LocationProvider(const LocationProvider& rhs);
352 // The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
354 LocationProvider& operator =(const LocationProvider& rhs);
357 class _LocationProviderImpl* __pImpl;
358 friend class _LocationProviderImpl;
359 }; //LocationProvider
360 }} // Tizen::Locations
361 #endif // _FLOC_LOCATION_PROVIDER_H_