wx小程序原生开发使用高德地图api
第一步:注册高德地图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)}})},