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!