Detailed explanation of WeChat mini-app map locating instance code

Source: Internet
Author: User
This article mainly introduces the information about simple examples for map locating of applets, and attaches the instance code and implementation, for more information about how to locate the instance code on the map of a small program, see the following article.

Map location for applet development.

It wasn't long before the mini-program was published. I learned the content for future development and wanted to lag behind others. here is a simple example of the mini-program. you can refer to it below.

GetLocation: function () {var that = this wx. getLocation ({success: function (res) {console. log (res) that. setData ({hasLocation: true, location: formatLocation (res. longpolling, res. latitude) // Here is the latitude and longitude })}})},


// Convert the longitude and latitude to the city name and street address. for details, refer to Baidu Map interface documentation :#


onLoad: function (options) {  console.log('onLoad')  var that = this;  wx.getLocation({    success: function (res) {      wx.request({        url: 'http://api.map.baidu.com/geocoder/v2/?ak=btsVVWf0TM1zUBEbzFz6QqWF&callback=renderReverse&location=' + res.latitude + ',' + res.longitude + '&output=json&pois=1', data: { },        header: { 'Content-Type': 'application/json' },        success: function(ops) {          console.log(ops.data)        }    })  // console.log(res)  // that.setData({  // hasLocation: true,  // location: formatLocation(res.longitude, res.latitude)  // })  }})}


Here, the mini-program documentation initiates an https request.

  
  
   
Region Selector
   
    
   
    
Current selection: {array [index]}
    
  
 
  
  
   
Time selector
   
    
   
    
Current selection: {time }}
    
  
 
  
  
   
Date selector
   
    
   
    
Current selection: {date }}
    
  
 Page ({data: {array: ['America ', 'China', 'Brazil', 'Japan '], index: 0, date: '2017-09-01', time: '12: 01'}, bindPickerChange: function (e) {console. log ('picker transmission selection changed, carrying value ', e. detail. value) this. setData ({index: e. detail. value})}, bindDateChange: function (e) {this. setData ({date: e. detail. value})}, bindTimeChange: function (e) {this. setData ({time: e. detail. value })}})


 
    
  
   
{Cityname }}
    
  
   
{Array [index]}
    
    
  
     
   
    
Switch city
     
  
 


Thank you for reading this article. I hope it will help you. thank you for your support for this site!

The above is a detailed description of the sample code for map locating in the applet. For more information, see other related articles in the first PHP community!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.