第一步:注冊高德地圖api的key
第二步:下載amap-wx.js 放到項目的某個目錄
第三步:配置app.json(必須,因為需要定位功能,)
"requiredPrivateInfos": ["getLocation"],"permission": {"scope.userLocation": {"desc": "初始化時獲取用戶的位置信息用于外出打卡定位"}}
否則會報錯如下:
getLocation:fail the api need to be declared in the requiredPrivateInfos field in app.json/ext.json
第四步:引入當前js文件,在使用
//頁面頂部引入:
var amapFile = require('../../utils/amap-wx.js');//如:..-/..-/libs/amap-wx.jsonLoad(options) {var that = this;var myAmapFun = new amapFile.AMapWX({key:'5ef5e008dfe21018204961b355e6b943'});myAmapFun.getWeather({success: function(data){console.log(data);},fail: function(info){//失敗回調console.log(info)}})},