在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 教程/ 嵌入式/ 使用本地API
避免300 ms點(diǎn)擊延遲
創(chuàng)建視圖
使用 Handlebars 模板
建立一個(gè)Cordova項(xiàng)目
使用照相機(jī)API
設(shè)置單頁應(yīng)用程序
執(zhí)行視圖路由
設(shè)置Workshop文件
創(chuàng)建一個(gè)Cordova項(xiàng)目
選擇一個(gè)數(shù)據(jù)存儲策略
使用聯(lián)系人API
使用本地API
使用本地通知
使用硬件加速

使用本地API

在本部分中,我增加了給員工添加他/她的位置信息標(biāo)簽的能力。在本示例應(yīng)用程序中,我們在一個(gè)警告中顯示原始信息(經(jīng)度/緯度)。在現(xiàn)實(shí)生活中的應(yīng)用程序中,我們通常在數(shù)據(jù)庫中保存位置信息作為員工信息的一部分,并在一張圖上顯示。

當(dāng)將應(yīng)用程序作為一個(gè)Cordova 應(yīng)用程序在你的設(shè)備上運(yùn)行時(shí),下面的這些代碼就會(huì)工作。當(dāng)頁面是由http:// 協(xié)議服務(wù)時(shí),這些代碼也會(huì)在桌面系統(tǒng)中的Chrome上工作,并且在Firefox中,忽視該協(xié)議(http:// 或 file://)。

步驟

1、增加geolocaton插件到你的項(xiàng)目中:

cordova plugin add org.apache.cordova.geolocation

2、在index.html中,增加以下列表項(xiàng)到employee-tpl模板:

<li class="table-view-cell media">
  <a hre="#" class="push-right add-location-btn">
      <span class="media-object pull-left"></span>
      <div class="media-body">
          Add location
      </div>
  </a>
</li>

3、在EmployeeView的initialize()函數(shù)中,為Add Location列表項(xiàng)的單擊事件注冊一個(gè)事件偵聽器。

this.$el.on('click', '.add-location-btn', this.addLocation);

確保你增加的這一行是作為initialize()函數(shù)的最后一行(在this.$el被分配以后)。

4、在EmployeeView中,定義addLocation 事件處理程序如下:

this.addLocation = function(event) {
  event.preventDefault();
  navigator.geolocation.getCurrentPosition(
      function(position) {
          alert(position.coords.latitude + ',' + position.coords.longitude);
      },
      function() {
          alert('Error getting location');
      });
  return false;
};

5、測試應(yīng)用程序。