In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)05/31 Report--
这篇"微信小程序怎么实现定位到当前城市功能"文章的知识点大部分人都不太理解,所以小编给大家总结了以下内容,内容详细,步骤清晰,具有一定的借鉴价值,希望大家阅读完这篇文章能有所收获,下面我们一起来看看这篇"微信小程序怎么实现定位到当前城市功能"文章吧。
微信小程序 定位到当前城市
首先需要申请百度地图Geocoding API
Geocoding API包括地址解析和逆地址解析功能:
1.地理编码:即地址解析,由详细到街道的结构化地址得到百度经纬度信息,例如:"北京市海淀区中关村南大街27号"地址解析的结果是"lng:116.31985,lat:39.959836"。同时,地理编码也支持名胜古迹、标志性建筑名称直接解析返回百度经纬度,例如:"百度大厦"地址解析的结果是"lng:116.30815,lat:40.056885" ,通用的POI检索需求,建议使用Place API。
2.逆地理编码:即逆地址解析,由百度经纬度信息得到结构化地址信息,例如:"lat:31.325152,lng:120.558957"逆地址解析的结果是"江苏省苏州市虎丘区塔园路318号"。
代码:
Page({ data:{ city:'' }, onLoad:function(options){ this.loadInfo(); }, loadInfo:function(){ var page=this wx.getLocation({ type: 'wgs84', // 默认为 wgs84 返回 gps 坐标,gcj02 返回可用于 wx.openLocation 的坐标 success: function(res){ // success var longitude=res.longitude var latitude=res.latitude page.loadCity(longitude,latitude) }, fail: function() { // fail }, complete: function() { // complete } }) }, loadCity:function(longitude,latitude){ var page =this wx.request({ url: 'https://api.map.baidu.com/geocoder/v2/?ak=您的ak &location='+latitude+','+longitude+'&output=json', data: {}, header:{ 'Content-Type':'application/json' }, success: function(res){ // success console.log(res); var city=res.data.result.addressComponent.city; page.setData({city:city}); }, fail: function() { // fail }, complete: function() { // complete } }) } })
index.wxml
{{city}} 以上就是关于"微信小程序怎么实现定位到当前城市功能"这篇文章的内容,相信大家都有了一定的了解,希望小编分享的内容对大家有帮助,若想了解更多相关的知识内容,请关注行业资讯频道。
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.