|
下面是如何使用的WiFi定位可以定期获得位置。这段代码将使您获得使用WiFi定位设备位置的定期更新。
PRIVILEGE需要:http://tizen.org/privilege/location
- // PRIVILEGE needed to be set in tizen-manifest.xml:
- // http://tizen.org/privilege/location
- #include <locations.h>
- #include <dlog.h> // for logging purposes
- // Declaring location Manager (in this example it is a global variable):
- location_manager_h location_manager;
- // Defining callback function for location update
- // The callback will be called periodically, as defined during callback registration.
- void position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
- {
- LOGI("Location update: Latitude: %f, Longitude: %f, timestamp: %d", latitude, longitude, timestamp);
- }
- // On startup of your service:
- void startup()
- {
- // Creating location manager for WiFi Positioning System
- // The LOCATIONS_METHOD_WPS setting means that this location manager will use
- // only WiFi networks to check the device's location.
- if(location_manager_create(LOCATIONS_METHOD_WPS, &location_manager) == LOCATIONS_ERROR_NONE)
- {
- LOGI("Location manager created.");
- // Setting callback for position update - update will be done every 15 seconds.
- if (location_manager_set_position_updated_cb(location_manager, position_updated_cb, 15, NULL) == LOCATIONS_ERROR_NONE)
- {
- LOGI("Location position update callback added.");
- }
- // Starting service
- if(location_manager_start(location_manager)== LOCATIONS_ERROR_NONE)
- {
- LOGI("Location service started.");
- }
- }
- }
- // On shutdown of your service:
- void shutdown()
- {
- //unset the callback
- if (location_manager_unset_position_updated_cb(location_manager) == LOCATIONS_ERROR_NONE)
- {
- LOGI("Callback unregistered.");
- }
- // It is not necessary to call location_manager_stop() just before calling
- // location_manager_destroy because the service is stopped automatically
- // before destruction.
- if (location_manager_destroy(location_manager) == LOCATIONS_ERROR_NONE)
- {
- LOGI("Location manager destroyed.");
- }
- location_manager = NULL;
- }
复制代码 |
|