geolocation.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342
  1. <!DOCTYPE HTML>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no">
  6. <meta name="HandheldFriendly" content="true">
  7. <meta name="MobileOptimized" content="320">
  8. <title>Geolocation Document</title>
  9. <link rel="stylesheet" type="text/css" href="res/doc.css" charset="utf-8">
  10. <link rel="stylesheet" type="text/css" href="res/prettify.sons.css" charset="utf-8">
  11. <script type="text/javascript" src="res/doc.js" charset="utf-8"></script><script type="text/javascript" src="res/prettify.js" charset="utf-8"></script>
  12. </head>
  13. <body><div id="content" class="content">
  14. <h1><a name="plus.geolocation">geolocation</a></h1>
  15. <p>Geolocation模块管理设备位置信息,用于获取地理位置信息,如经度、纬度等。通过plus.geolocation可获取设备位置管理对象。虽然W3C已经提供标准API获取位置信息,但在某些平台存在差异或未实现,为了保持各平台的统一性,定义此规范接口获取位置信息。</p>
  16. <h2>方法:</h2>
  17. <ul>
  18. <li>
  19. <a href="#plus.geolocation.getCurrentPosition">getCurrentPosition</a>: 获取当前设备位置信息</li>
  20. <li>
  21. <a href="#plus.geolocation.watchPosition">watchPosition</a>: 监听设备位置变化信息</li>
  22. <li>
  23. <a href="#plus.geolocation.clearWatch">clearWatch</a>: 关闭监听设备位置信息</li>
  24. </ul>
  25. <h2>对象:</h2>
  26. <ul>
  27. <li>
  28. <a href="#plus.geolocation.Position">Position</a>: JSON对象,设备位置信息数据</li>
  29. <li>
  30. <a href="#plus.geolocation.Address">Address</a>: JSON对象,地址信息</li>
  31. <li>
  32. <a href="#plus.geolocation.Coordinates">Coordinates</a>: JSON对象,地理坐标信息</li>
  33. <li>
  34. <a href="#plus.geolocation.PositionOptions">PositionOptions</a>: JSON对象,监听设备位置信息参数</li>
  35. <li>
  36. <a href="#plus.geolocation.GeolocationError">GeolocationError</a>: JSON对象,定位错误信息</li>
  37. </ul>
  38. <h2>回调方法:</h2>
  39. <ul>
  40. <li>
  41. <a href="#plus.geolocation.GeolocationSuccessCallback">GeolocationSuccessCallback</a>: 获取设备位置信息成功的回调函数</li>
  42. <li>
  43. <a href="#plus.geolocation.GeolocationErrorCallback">GeolocationErrorCallback</a>: 获取设备位置信息失败的回调函数</li>
  44. </ul>
  45. <h2>权限:</h2>
  46. <p>5+功能模块(permissions)</p>
  47. <pre class="prettyprint linenums">
  48. {
  49. // ...
  50. "permissions":{
  51. // ...
  52. "Geolocation": {
  53. "description": "位置信息"
  54. }
  55. }
  56. }
  57. </pre>
  58. <h1><a name="plus.geolocation.Position">Position</a></h1>
  59. <p>JSON对象,设备位置信息数据</p>
  60. <pre class="prettyprint linenums">
  61. interface Position {
  62. readonly attribute Coordinates coords;
  63. readonly attribute String coordsType;
  64. readonly attribute Number timestamp;
  65. readonly attribute Address address;
  66. readonly attribute String addresses;
  67. }
  68. </pre>
  69. <h2>属性:</h2>
  70. <ul>
  71. <li>coords: <em>(<a href="#plus.geolocation.Coordinates">Coordinates</a>
  72. 类型
  73. )</em>地理坐标信息,包括经纬度、海拔、速度等信息<br>
  74. </li>
  75. <li>coordsType: <em>(<font class="type">String</font>
  76. 类型
  77. )</em>获取到地理坐标信息的坐标系类型<br><p>
  78. 可取以下坐标系类型:
  79. "wgs84":表示WGS-84坐标系;
  80. "gcj02":表示国测局经纬度坐标系;
  81. "bd09":表示百度墨卡托坐标系,仅百度定位支持;
  82. "bd09ll":表示百度经纬度坐标系,仅百度定位支持。
  83. </p>
  84. </li>
  85. <li>timestamp: <em>(<font class="type">Number</font>
  86. 类型
  87. )</em>获取到地理坐标的时间戳信息<br><p>
  88. 时间戳值为从1970年1月1日至今的毫秒数。
  89. </p>
  90. </li>
  91. <li>address: <em>(<a href="#plus.geolocation.Address">Address</a>
  92. 类型
  93. )</em>获取到地理位置对应的地址信息<br><p>
  94. 获取地址信息需要连接到服务器进行解析,所以会消耗更多的资源,如果不需要获取地址信息可通过设置PositionOptions参数的geocode属性值为false避免获取地址信息。
  95. 如果没有获取到地址信息则返回undefined。
  96. </p>
  97. </li>
  98. <li>addresses: <em>(<font class="type">String</font>
  99. 类型
  100. )</em>获取完整地址描述信息<br><p>
  101. 如果没有获取到地址信息则返回undefined。
  102. </p>
  103. </li>
  104. </ul>
  105. <h1><a name="plus.geolocation.Address">Address</a></h1>
  106. <p>JSON对象,地址信息</p>
  107. <pre class="prettyprint linenums">
  108. interface Address {
  109. readonly attribute String country;
  110. readonly attribute String province;
  111. readonly attribute String city;
  112. readonly attribute String district;
  113. readonly attribute String street;
  114. readonly attribute String streetNum;
  115. readonly attribute String poiName;
  116. readonly attribute String postalCode;
  117. readonly attribute String cityCode;
  118. }
  119. </pre>
  120. <h2>属性:</h2>
  121. <ul>
  122. <li>country: <em>(<font class="type">String</font>
  123. 类型
  124. )</em>国家<br><p>
  125. 如“中国”,如果无法获取此信息则返回undefined。
  126. </p>
  127. </li>
  128. <li>province: <em>(<font class="type">String</font>
  129. 类型
  130. )</em>省份名称<br><p>
  131. 如“北京市”,如果无法获取此信息则返回undefined。
  132. </p>
  133. </li>
  134. <li>city: <em>(<font class="type">String</font>
  135. 类型
  136. )</em>城市名称<br><p>
  137. 如“北京市”,如果无法获取此信息则返回undefined。
  138. </p>
  139. </li>
  140. <li>district: <em>(<font class="type">String</font>
  141. 类型
  142. )</em>区(县)名称<br><p>
  143. 如“朝阳区”,如果无法获取此信息则返回undefined。
  144. </p>
  145. </li>
  146. <li>street: <em>(<font class="type">String</font>
  147. 类型
  148. )</em>街道信息<br><p>
  149. 如“酒仙桥路”,如果无法获取此信息则返回undefined。
  150. </p>
  151. </li>
  152. <li>streetNum: <em>(<font class="type">String</font>
  153. 类型
  154. )</em>获取街道门牌号信息<br><p>
  155. 如“3号”,如果无法获取此信息则返回undefined。
  156. </p>
  157. </li>
  158. <li>poiName: <em>(<font class="type">String</font>
  159. 类型
  160. )</em>POI信息<br><p>
  161. 如“电子城.国际电子总部”,如果无法获取此信息则返回undefined。
  162. </p>
  163. </li>
  164. <li>postalCode: <em>(<font class="type">String</font>
  165. 类型
  166. )</em>邮政编码<br><p>
  167. 如“100016”,如果无法获取此信息则返回undefined。
  168. </p>
  169. </li>
  170. <li>cityCode: <em>(<font class="type">String</font>
  171. 类型
  172. )</em>城市代码<br><p>
  173. 如“010”,如果无法获取此信息则返回undefined。
  174. </p>
  175. </li>
  176. </ul>
  177. <h1><a name="plus.geolocation.Coordinates">Coordinates</a></h1>
  178. <p>JSON对象,地理坐标信息</p>
  179. <pre class="prettyprint linenums">
  180. interface Coordinates {
  181. readonly attribute double latitude;
  182. readonly attribute double longitude;
  183. readonly attribute double altitude;
  184. readonly attribute double accuracy;
  185. readonly attribute double altitudeAccuracy;
  186. readonly attribute double heading;
  187. readonly attribute double speed;
  188. }
  189. </pre>
  190. <h2>属性:</h2>
  191. <ul>
  192. <li>latitude: <em>(<font class="type">Number</font>
  193. 类型
  194. )</em>坐标纬度值<br><p>数据类型对象,地理坐标中的纬度值。</p>
  195. </li>
  196. <li>longitude: <em>(<font class="type">Number</font>
  197. 类型
  198. )</em>坐标经度值<br><p>数据类型对象,地理坐标中的经度值。</p>
  199. </li>
  200. <li>altitude: <em>(<font class="type">Number</font>
  201. 类型
  202. )</em>海拔信息<br><p>数据类型对象,如果无法获取此信息,则此值为空(null)。</p>
  203. </li>
  204. <li>accuracy: <em>(<font class="type">Number</font>
  205. 类型
  206. )</em>地理坐标信息的精确度信息<br><p>数据类型对象,单位为米,其有效值必须大于0。</p>
  207. </li>
  208. <li>altitudeAccuracy: <em>(<font class="type">Number</font>
  209. 类型
  210. )</em>海拔的精确度信息<br><p>数据类型对象,单位为米,其有效值必须大于0。如果无法获取海拔信息,则此值为空(null)。</p>
  211. </li>
  212. <li>heading: <em>(<font class="type">Number</font>
  213. 类型
  214. )</em>表示设备移动的方向<br><p>
  215. 数据类型对象,范围为0到360,表示相对于正北方向的角度。如果无法获取此信息,则此值为空(null)。如果设备没有移动则此值为NaN。
  216. </p>
  217. </li>
  218. <li>speed: <em>(<font class="type">Number</font>
  219. 类型
  220. )</em>表示设备移动的速度<br><p>
  221. 数据类型对象,单位为米每秒(m/s),其有效值必须大于0。如果无法获取速度信息,则此值为空(null)。
  222. </p>
  223. </li>
  224. </ul>
  225. <h1><a name="plus.geolocation.PositionOptions">PositionOptions</a></h1>
  226. <p>JSON对象,监听设备位置信息参数</p>
  227. <h2>属性:</h2>
  228. <ul>
  229. <li>enableHighAccuracy: <em>(<font class="type">Boolean</font>
  230. 类型
  231. )</em>是否高精确度获取位置信息<br><p>高精度获取表示需要使用更多的系统资源,默认值为false。</p>
  232. </li>
  233. <li>timeout: <em>(<font class="type">Number</font>
  234. 类型
  235. )</em>获取位置信息的超时时间<br><p>单位为毫秒(ms),默认值为不超时。如果在指定的时间内没有获取到位置信息则触发错误回调函数。</p>
  236. </li>
  237. <li>maximumAge: <em>(<font class="type">Number</font>
  238. 类型
  239. )</em>获取位置信息的间隔时间<br><p>
  240. 单位为毫秒(ms),默认值为5000(即5秒)。调用plus.geolocation.watchPosition时为更新位置信息的间隔时间。
  241. 注意:在不同定位模块下支持范围值可能不同,如百度定位模块的间隔范围为大于等于1秒,如果设置的值小于最小值则使用最小值。
  242. </p>
  243. </li>
  244. <li>provider: <em>(<font class="type">String</font>
  245. 类型
  246. )</em>优先使用的定位模块<br><p>
  247. 可取以下供应者:
  248. "system":表示系统定位模块,支持wgs84坐标系;
  249. "baidu":表示百度定位模块,支持gcj02/bd09/bd09ll坐标系;
  250. "amap":表示高德定位模块,支持gcj02坐标系。
  251. 默认值按以下优先顺序获取(amap&gt;baidu&gt;system),若指定的provider不存在或无效则返回错误回调。
  252. 注意:百度/高德定位模块需要配置百度/高德地图相关参数才能正常使用。
  253. </p>
  254. </li>
  255. <li>coordsType: <em>(<font class="type">String</font>
  256. 类型
  257. )</em>指定获取的定位数据坐标系类型<br><p>
  258. 可取以下坐标系类型:
  259. "wgs84":表示WGS-84坐标系;
  260. "gcj02":表示国测局经纬度坐标系;
  261. "bd09":表示百度墨卡托坐标系;
  262. "bd09ll":表示百度经纬度坐标系;
  263. provider为"system"时,支持wgs84坐标系,默认使用"wgs84"坐标系;
  264. provider为"baidu"时,支持gcj02/bd09/bd09ll坐标系,默认使用"gcj02"坐标系;
  265. provider为"amap"时,支持gcj02坐标系,默认使用"gcj02"坐标系。
  266. 如果设置的坐标系类型provider不支持,则返回错误。
  267. </p>
  268. </li>
  269. <li>geocode: <em>(<font class="type">Boolean</font>
  270. 类型
  271. )</em>是否解析地址信息<br><p>
  272. 解析的地址信息保存到Position对象的address、addresses属性中,true表示解析地址信息,false表示不解析地址信息,返回的Position对象的address、addresses属性值为undefined,默认值为true。
  273. 如果解析地址信息失败则返回的Position对象的address、addresses属性值为null。
  274. </p>
  275. </li>
  276. </ul>
  277. <h1><a name="plus.geolocation.GeolocationError">GeolocationError</a></h1>
  278. <p>JSON对象,定位错误信息</p>
  279. <pre class="prettyprint linenums">
  280. interface GeolocationError {
  281. const Number PERMISSION_DENIED = 1;
  282. const Number POSITION_UNAVAILABLE = 2;
  283. const Number TIMEOUT = 3;
  284. const Number UNKNOWN_ERROR = 4;
  285. readonly attribute Number code;
  286. readonly attribute String message;
  287. }
  288. </pre>
  289. <h2>属性:</h2>
  290. <ul>
  291. <li>code: <em>(<font class="type">Number</font>
  292. 类型
  293. )</em>错误代码<br><p>
  294. 取值范围为GeolocationError对象的常量值。
  295. </p>
  296. </li>
  297. <li>message: <em>(<font class="type">String</font>
  298. 类型
  299. )</em>错误描述信息<br><p>
  300. 详细错误描述信息。
  301. </p>
  302. </li>
  303. </ul>
  304. <h1><a name="plus.geolocation.GeolocationSuccessCallback">GeolocationSuccessCallback</a></h1>
  305. <p>获取设备位置信息成功的回调函数</p>
  306. <pre class="prettyprint linenums">
  307. void onSuccess( position ) {
  308. // Get Position code.
  309. }
  310. </pre>
  311. <h2>参数:</h2>
  312. <ul><li>position:
  313. <em>(
  314. <a href="#plus.geolocation.Position">Position</a>
  315. )
  316. 必选 </em>设备的地理位置信息,参考Position<br>
  317. </li></ul>
  318. <h2>返回值:</h2>
  319. <font class="type">void</font>
  320. : 无<h1><a name="plus.geolocation.GeolocationErrorCallback">GeolocationErrorCallback</a></h1>
  321. <p>获取设备位置信息失败的回调函数</p>
  322. <pre class="prettyprint linenums">
  323. function void onGeolocationError( GeolocationError error ) {
  324. // Handle error
  325. var code = error.code; // 错误编码
  326. var message = error.message; // 错误描述信息
  327. }
  328. </pre>
  329. <h2>参数:</h2>
  330. <ul><li>error:
  331. <em>(
  332. <a href="#plus.geolocation.GeolocationError">GeolocationError</a>
  333. )
  334. 必选 </em>获取位置操作的错误信息<br>
  335. 可通过error.code(Number类型)获取错误编码;
  336. 可通过error.message(String类型)获取错误描述信息。
  337. </li></ul>
  338. <h2>返回值:</h2>
  339. <font class="type">void</font>
  340. : 无<br><br>
  341. </div></body>
  342. </html>