找回密码
 立即注册
查看: 2805|回复: 0

获得应用使用的位置(无线定位系统)

[复制链接]
发表于 2015-8-12 13:36:32 | 显示全部楼层 |阅读模式
下面是如何使用的WiFi定位可以定期获得位置。这段代码将使您获得使用WiFi定位设备位置的定期更新。
PRIVILEGE需要:http://tizen.org/privilege/location
  1. //    PRIVILEGE needed to be set in tizen-manifest.xml:
  2. //    http://tizen.org/privilege/location

  3. #include <locations.h>
  4. #include <dlog.h> // for logging purposes

  5. // Declaring location Manager (in this example it is a global variable):
  6. location_manager_h location_manager;

  7. // Defining callback function for location update
  8. // The callback will be called periodically, as defined during callback registration.
  9. void position_updated_cb(double latitude, double longitude, double altitude, time_t timestamp, void *user_data)
  10. {
  11.     LOGI("Location update: Latitude: %f, Longitude: %f, timestamp: %d", latitude, longitude, timestamp);
  12. }

  13. // On startup of your service:

  14. void startup()
  15. {
  16.     // Creating location manager for WiFi Positioning System
  17.     // The LOCATIONS_METHOD_WPS setting means that this location manager will use
  18.     // only WiFi networks to check the device's location.
  19.     if(location_manager_create(LOCATIONS_METHOD_WPS, &location_manager) == LOCATIONS_ERROR_NONE)
  20.     {
  21.         LOGI("Location manager created.");
  22.         // Setting callback for position update - update will be done every 15 seconds.
  23.         if (location_manager_set_position_updated_cb(location_manager, position_updated_cb, 15, NULL) == LOCATIONS_ERROR_NONE)
  24.         {
  25.             LOGI("Location position update callback added.");
  26.         }
  27.         // Starting service
  28.         if(location_manager_start(location_manager)== LOCATIONS_ERROR_NONE)
  29.         {
  30.             LOGI("Location service started.");
  31.         }
  32.     }
  33. }

  34. // On shutdown of your service:

  35. void shutdown()
  36. {
  37.     //unset the callback
  38.     if (location_manager_unset_position_updated_cb(location_manager) == LOCATIONS_ERROR_NONE)
  39.     {
  40.         LOGI("Callback unregistered.");
  41.     }
  42.     // It is not necessary to call location_manager_stop() just before calling
  43.     // location_manager_destroy because the service is stopped automatically
  44.     // before destruction.
  45.     if (location_manager_destroy(location_manager) == LOCATIONS_ERROR_NONE)
  46.     {
  47.         LOGI("Location manager destroyed.");
  48.     }
  49.     location_manager = NULL;
  50. }
复制代码
欢迎来到泰泽网:http://www.tizennet.com/ 泰泽论坛:http://bbs.tizennet.com/ 好没有内涵哦,快到设置中更改这个无聊的签名吧!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|泰泽应用|泰泽论坛|泰泽网|小黑屋|Archiver|手机版|泰泽邮箱|泰泽网 ( 蜀ICP备13024062号-1 )

GMT+8, 2024-12-26 01:29 , Processed in 0.051568 second(s), 20 queries .

Powered by Discuz! X3.5

© 2001-2024 Discuz! Team.

快速回复 返回顶部 返回列表