武装少女在线观看高清完整版免费,丝袜+亚洲区,少妇被cao高潮呻吟声,午夜伦情电午夜伦情电影,日日躁夜夜躁狠狠躁

小程序模板網(wǎng)

微信小程序?qū)崙?zhàn)教程:從零開始制作一個跑步微信小程序

發(fā)布時(shí)間:2018-04-03 14:20 所屬欄目:小程序開發(fā)教程

前言

我已經(jīng)把全部代碼放在github上-weChatApp-Run,可以下載來看看或者先star收藏,我以后還會進(jìn)行一些優(yōu)化更新?,F(xiàn)在只是一個學(xué)習(xí)Demo,大家溝通學(xué)習(xí),實(shí)際應(yīng)用還需更多優(yōu)化。

正文

一、準(zhǔn)備工作

1、注冊一個小程序賬號,得用一個沒注冊過公眾號的郵箱注冊。
2、注冊過程中需要很多認(rèn)證,有很多認(rèn)證,比較繁瑣,如果暫時(shí)只是開發(fā)測試,不進(jìn)行提審、發(fā)布的話,只要完成營業(yè)執(zhí)照號填寫就可以了,不需要完成微信認(rèn)證。
3、注冊完賬號,登錄,在主頁面左邊列表中點(diǎn)擊設(shè)置,然后再設(shè)置頁面中選開發(fā)設(shè)置就可以看到AppID,用于登錄開發(fā)工具。

 

 

二、開發(fā)工具

可以到官網(wǎng)下載開發(fā)工具下載

 

三、開始項(xiàng)目

打開開發(fā)者工具,選擇小程序選項(xiàng),到達(dá)添加項(xiàng)目頁面

 

這個時(shí)候在前面設(shè)置頁面的AppId就用到了。

如果項(xiàng)目目錄中的文件是個空文件夾,會提示是否創(chuàng)建quick start 項(xiàng)目。
選擇“是”,開發(fā)者工具會幫助我們在開發(fā)目錄里生成一個簡單的 demo。
這個Demo擁有一個完整的小程序的大概框架。

1、框架

先看下一目錄:

 

app.js: 小程序邏輯,生命周期,,全局變量
app.json: 小程序公共設(shè)置,導(dǎo)航欄顏色等,不可以注釋
app.wxss :小程序公共樣式,類CSS 。

小程序頁面構(gòu)成:

頁面構(gòu)成

每一個小程序頁面是由同路徑下同名的四個不同后綴文件的組成,如:index.js、index.wxml、index.wxss、index.json。

 

微信小程序中的每一個頁面的【路徑+頁面名】都需要寫在 app.json 的 pages 中,且 pages 中的第一個頁面是小程序的首頁。

路徑

這四個文件按照功能可以分成三個部分:

配置:json 文件
邏輯層:js文件
視圖層:wxss.wxml文件

在 iOS 上,小程序的 javascript 代碼是運(yùn)行在 JavaScriptCore 中
在 Android 上,小程序的 javascript 代碼是通過 X5 內(nèi)核來解析
在 開發(fā)工具上, 小程序的 javascript 代碼是運(yùn)行在 nwjs(chrome內(nèi)核) 中。所以開發(fā)工具上的效果跟實(shí)際效果有所出入。

2、組件

微信提供了許多組件,主要分為八種:

視圖容器、
基礎(chǔ)內(nèi)容、
表單組件、
操作反饋、
導(dǎo)航、
媒體組件、
地圖、
畫布

包含view、scroll-view、button、form等普通常用的組件,也提供了地圖map、畫布canvas。

組件主要屬于視圖層,通過wxml來進(jìn)行結(jié)構(gòu)布局,類似于html。通過wxss修改樣式,類似于css。
組件使用語法實(shí)例:



<!--普通視圖-->
<view>這是一個普通視圖</view>

<!--wxss樣式修改-->
<view clas="mainView">樣式修改過的視圖</view>

更多的組件以及相關(guān)使用方法可以到官方文檔-組件查看

3、API

網(wǎng)絡(luò)
媒體
數(shù)據(jù)
位置
設(shè)備
界面
開發(fā)接口

其中網(wǎng)絡(luò)請求的使用必須先到公眾平臺登錄小程序賬號,在設(shè)置頁面那里,設(shè)置允許訪問的域名,網(wǎng)絡(luò)請求包含了普通的http請求、支持上傳、下載、socket。基本上滿足了我們開發(fā)中所需要的網(wǎng)絡(luò)需求。

這些API屬于邏輯層,寫在js文件中,
使用實(shí)例:



wx.getLocation({
   type: 'wgs84',
   success: function(res) {
       var latitude = res.latitude 
       var longitude = res.longitude 
       var speed = res.speed 
       var accuracy = res.accuracy 
}})

可以到官方文檔-API查看其它API的使用方法。

4、編譯運(yùn)行

1、模擬器
可以在模擬器上看效果,上面降到了運(yùn)行底層不同,效果跟在手機(jī)上運(yùn)行有些差異

 

2、真機(jī)
在左邊的選項(xiàng)欄中,選擇項(xiàng)目,然后點(diǎn)預(yù)覽會生產(chǎn)一個二維碼,用管理員微信號掃一掃就可以在真機(jī)上看實(shí)際效果

 

實(shí)踐--跑步小程序。

真機(jī)運(yùn)行截圖(運(yùn)行于iPhone7,微信版本:6.3.30):

 

 

 

 

功能:

能夠計(jì)算里程、時(shí)間、實(shí)時(shí)獲取跑步路徑(有些粗糙)

思路:

主要使用了微信小程序的獲取位置APIwx.getLocation()和地圖組件map。
首先實(shí)現(xiàn)一個計(jì)時(shí)器進(jìn)行 計(jì)時(shí),通過wx.getLocation()獲取坐標(biāo),把獲取到的坐標(biāo)存在一個數(shù)組中,通過坐標(biāo)每隔一段時(shí)間獲取里程,進(jìn)行累加得到總里程,同時(shí)也通過坐標(biāo)點(diǎn)進(jìn)行連線
存在的問題:
1、因?yàn)槟壳罢也坏皆诘貓D上畫連線的方法,所以采用了在地圖上貼小紅點(diǎn)圖的方法顯示大概跑步路徑,路徑比較粗糙。
2、雖然采用了API里面的火星坐標(biāo)gcj02類型,但是獲取的坐標(biāo)跟國際坐標(biāo)差不多,依然存在著偏差。

核心代碼:

我把全部代碼放在github上-weChatApp-Run,可以下載來看看或者先star收藏,我以后還會進(jìn)行一些優(yōu)化更新?,F(xiàn)在只是一個學(xué)習(xí)Demo,大家溝通學(xué)習(xí),實(shí)際應(yīng)用還需更多優(yōu)化。

wxml文件布局代碼:



<view class="head" style="flex-direction:row;">
    <image class="icon" src="/resources/joyrun.png" mode="aspectFill"/>
    <button bindtap="openLocation">打開位置</button>
    <button bindtap="starRun">開始跑步</button>
    <button bindtap="stopRun">暫停跑步</button>
    <text>\\n里程數(shù):{{meters}}km</text>
    <text>\\n\\n時(shí)間:{{time}}</text>
</view>

<view class="mainView">
   <map
        class="mapView"
        style="width: 100%; height: 375px;"
        latitude="{{latitude}}"
        longitude="{{longitude}}"
        markers="{{markers}}"
        covers="{{covers}}"
        >
    </map>

</view>

js文件邏輯代碼:



var countTooGetLocation = 0;
var total_micro_second = 0;
var starRun = 0;
var totalSecond  = 0;
var oriMeters = 0.0;
/* 毫秒級倒計(jì)時(shí) */
function count_down(that) {

    if (starRun == 0) {
      return;
    }

    if (countTooGetLocation >= 100) {
      var time = date_format(total_micro_second);
      that.updateTime(time);
    }

      if (countTooGetLocation >= 5000) { //1000為1s
        that.getLocation();
        countTooGetLocation = 0;
      }   


 setTimeout
      setTimeout(function(){
        countTooGetLocation += 10;
    total_micro_second += 10;
        count_down(that);
    }
    ,10
    )
}


// 時(shí)間格式化輸出,如03:25:19 86。每10ms都會調(diào)用一次
function date_format(micro_second) {
      // 秒數(shù)
      var second = Math.floor(micro_second / 1000);
      // 小時(shí)位
      var hr = Math.floor(second / 3600);
      // 分鐘位
      var min = fill_zero_prefix(Math.floor((second - hr * 3600) / 60));
      // 秒位
    var sec = fill_zero_prefix((second - hr * 3600 - min * 60));// equal to => var sec = second % 60;


    return hr + ":" + min + ":" + sec + " ";
}


function getDistance(lat1, lng1, lat2, lng2) { 
    var dis = 0;
    var radLat1 = toRadians(lat1);
    var radLat2 = toRadians(lat2);
    var deltaLat = radLat1 - radLat2;
    var deltaLng = toRadians(lng1) - toRadians(lng2);
    var dis = 2 * Math.asin(Math.sqrt(Math.pow(Math.sin(deltaLat / 2), 2) + Math.cos(radLat1) * Math.cos(radLat2) * Math.pow(Math.sin(deltaLng / 2), 2)));
    return dis * 6378137;

    function toRadians(d) {  return d * Math.PI / 180;}
} 

function fill_zero_prefix(num) {
    return num < 10 ? "0" + num : num
}

//****************************************************************************************
//****************************************************************************************

Page({
  data: {
    clock: '',
    isLocation:false,
    latitude: 0,
    longitude: 0,
    markers: [],
    covers: [],
    meters: 0.00,
    time: "0:00:00"
  },

//****************************
  onLoad:function(options){
    // 頁面初始化 options為頁面跳轉(zhuǎn)所帶來的參數(shù)
    this.getLocation()
    console.log("onLoad")
    count_down(this);
  },
  //****************************
  openLocation:function (){
    wx.getLocation({
      type: 'gcj02', // 默認(rèn)為 wgs84 返回 gps 坐標(biāo),gcj02 返回可用于 wx.openLocation 的坐標(biāo)
      success: function(res){
          wx.openLocation({
            latitude: res.latitude, // 緯度,范圍為-90~90,負(fù)數(shù)表示南緯
            longitude: res.longitude, // 經(jīng)度,范圍為-180~180,負(fù)數(shù)表示西經(jīng)
            scale: 28, // 縮放比例
          })
      },
    })
  },


//****************************
  starRun :function () {
    if (starRun == 1) {
      return;
    }
    starRun = 1;
    count_down(this);
    this.getLocation();
  },


 //****************************
  stopRun:function () {
    starRun = 0;
    count_down(this);
  },


//****************************
  updateTime:function (time) {

    var data = this.data;
    data.time = time;
    this.data = data;
    this.setData ({
      time : time,
    })

  },


//****************************
  getLocation:function () {
    var that = this
    wx.getLocation({

      type: 'gcj02', // 默認(rèn)為 wgs84 返回 gps 坐標(biāo),gcj02 返回可用于 wx.openLocation 的坐標(biāo)
      success: function(res){
        console.log("res----------")
        console.log(res)

        //make datas 
        var newCover = {
            latitude: res.latitude,
            longitude: res.longitude,
            iconPath: '/resources/redPoint.png',
          };
        var oriCovers = that.data.covers;

        console.log("oriMeters----------")
        console.log(oriMeters);
        var len = oriCovers.length;
        var lastCover;
        if (len == 0) {
          oriCovers.push(newCover);
        }
        len = oriCovers.length;
        var lastCover = oriCovers[len-1];

        console.log("oriCovers----------")
        console.log(oriCovers,len);

        var newMeters = getDistance(lastCover.latitude,lastCover.longitude,res.latitude,res.longitude)/1000;

        if (newMeters < 0.0015){
            newMeters = 0.0;
        }

        oriMeters = oriMeters + newMeters; 
        console.log("newMeters----------")
        console.log(newMeters);


        var meters = new Number(oriMeters);
        var showMeters = meters.toFixed(2);

        oriCovers.push(newCover);

        that.setData({
          latitude: res.latitude,
          longitude: res.longitude,
          markers: [],
          covers: oriCovers,
          meters:showMeters,
        });
      },
    })
  }

})

五、后語

本文是一個快速上手開發(fā)的介紹,細(xì)節(jié)介紹可以查看官方文檔


易優(yōu)小程序(企業(yè)版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.kknew.com.cn/wxmini/doc/course/23052.html 復(fù)制鏈接 如需定制請聯(lián)系易優(yōu)客服咨詢: 點(diǎn)擊咨詢
在線客服
易小優(yōu)
轉(zhuǎn)人工 ×