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)06/01 Report--
This article mainly explains "how to position Mini Program in the current city". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "how Mini Program locates the current city".
First, you need to apply for Baidu Map Geocoding API.
Geocoding API includes address resolution and inverse address resolution functions:
1. Geocoding: address resolution, from the details to the structured address of the street to get Baidu longitude and latitude information, for example: "27 Zhongguancun South Street, Haidian District, Beijing" the result of address resolution is "lng:116.31985,lat:39.959836". At the same time, geocoding also supports the direct resolution of the names of places of interest and landmarks to return to Baidu longitude and latitude. For example, the result of address resolution of "Baidu Tower" is "lng:116.30815,lat:40.056885". For general POI retrieval requirements, it is recommended to use Place API.
two。 Inverse geocoding: that is, inverse address resolution. Structured address information is obtained from Baidu longitude and latitude information. For example, the result of inverse address resolution of "lat:31.325152,lng:120.558957" is "No. 318 Tayuan Road, Huqiu District, Suzhou City, Jiangsu Province".
Code:
12 34 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 26 27 28 30 31 32 33 36 37 38 39 40 41 42 43 44 45 46 47 48Page ({data: {city:''}, onLoad:function (options) {this.loadInfo () }, loadInfo:function () {var page=this wx.getLocation ({type: 'wgs84', / / defaults to wgs84 returns gps coordinates Gcj02 returns the coordinates available for 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= your 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
1 2 3 4 {{city}} so far, I believe you have a deeper understanding of "how Mini Program locates the current city". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.