关于首页导航 tabBar
"tabBar": {
"backgroundColor": "#fafafa",
"borderStyle": "white",
"selectedColor": "#b4282d",
"color": "#666",
"list": [
{
"pagePath": "pages/index/index",
"text": "首页",
"iconPath": "/images/ic_menu_choice_nor.png",
"selectedIconPath": "/images/ic_menu_choice_pressed.png"
},
{
"pagePath": "pages/topic/topic",
"text": "专题",
"iconPath": "/images/ic_menu_topic_nor.png",
"selectedIconPath": "/images/ic_menu_topic_pressed.png"
},
{
"pagePath": "pages/category/category",
"text": "分类",
"iconPath": "/images/ic_menu_sort_nor.png",
"selectedIconPath": "/images/ic_menu_sort_pressed.png"
}
]
},
list中必须是大于二小于5的,在app.json中设置
微信小程序中允许访问位置
在app.json中设置 "sitemapLocation": "sitemap.json", "permission": { "scope.userLocation": { "desc": "你的位置信息将用于小程序位置接口的效果展示" } }
当需要访问位置时,会弹出此消息
获取地点的经纬度 使用 wx.getLocation({})方法
wx.getLocation({
// success: function(res) {
// console.log(res.latitude) //纬度
// console.log(res.longitude)//经度
})
一个小例子,利用api接口,先获取经纬度,将经纬度作为参数再传给API接口
onLoad: function () {
var that = this;
wx.getLocation({
success: function(res) {
console.log(res.latitude)
console.log(res.longitude)
wx.request({
url: `http://apis.juhe.cn/geo/?key=f7e239e85eda5324a999af579a713a38&lat=${res.latitude}&lng=${res.longitude}&type=1`,
success: function(data) {
console.log(data)
that.setData({
address: data.data.result.address
})
}
})
},