微信模拟定位,微信小程序实现自动定位
使用了腾讯地图提供的免费api:需要引入一个js文件:js代码://引入SDK核心类varQQMapWX=require('../../libs/qqmap-wx-jssdk.js');varqqmap=newQQMapWX({//在腾讯地图开放平台申请密钥http://lbs.qq.com/mykey.htmlkey:'yourKEY'});Page({data:{myLatitude:"",myLongitude:"",myAddress:""},onLoad:function(){varthat=this//用微信提供的api获取经纬度wx.getLocation({type:'wgs84',success:function(res){that.setData({myLatitude:res.latitude,myLongitude:res.longitude})//用腾讯地图的api,根据经纬度获取城市qqmap.reverseGeocoder({location:{latitude:that.data.myLatitude,longitude:that.data.myLongitude},success:function(res){console.log(res)vara=res.result.address_component//获取市和区(区可能为空)that.setData({myAddress:a.city+a.district})//控制台输出结果console.log(that.data.myAddress)}})}})}})
声明:本站所有文章资源内容,如无特殊说明或标注,均为采集网络资源。如若本站内容侵犯了原著者的合法权益,可联系本站删除。

