为代码:Page({ /** * 页面的初始数据 */ data: { //经纬度 latitude: 45.745842, longitude: 127.212255, markers: [{ latitude: 45.745842, longitude: 127.212255, width: 35, height: 50 }] }, onLoad: function() { var that = this; wx.getLocation({ type: 'gcj02', success: function(res) { that.setData({ latitude: res.latitude, longitude: res.longitude, }); } }); }, moveToLocation() { let that = this; wx.chooseLocation({ success: function (res) { console.log(res.name); that.setData({ mapName: res.name, latitude: res.latitude, longitude: res.longitude, markers: [{ latitude: res.latitude, longitude: res.longitude, width: 35, height: 50 }] }); }, fail: function () { console.log(err); } }); }, locateMe: function() { let that = this; wx.getLocation({ type: 'gcj02', success: function(res) { that.setData({ latitude: res.latitude, longitude: res.longitude, markers: [{ id: 0, latitude: res.latitude, longitude: res.longitude, width: 35, height: 50 }] }); }, fail: function() { console.log(err); }, }); }, onSearchInputChange: function(event) { var that = this; var searchValue = event.detail.value; if (searchValue) { wx.getLocation({ type: 'gcj02', success: function(res) { var latitude = res.latitude; var longitude = res.longitude; var marker = { id: 0, latitude: latitude, longitude: longitude, width: 50, height: 50, }; this.setData({ longitude: longitude, latitude: latitude, markers: [marker] }); } }); } } })添加注释
时间: 2024-02-10 12:32:26 浏览: 69
gci16.fossasia.org:FOSSASIA Google代码输入网站201617 http://gci16.fossasia.org
/*
该代码实现了一个小程序页面的地图定位功能,包括以下几个函数:
1. onLoad:页面加载时获取用户的地理位置信息,并在地图上显示出来;
2. moveToLocation:让用户手动选择一个地点并在地图上标记出来;
3. locateMe:重新获取用户的地理位置信息,并在地图上显示出来;
4. onSearchInputChange:当用户在搜索框中输入关键字时,根据关键字在地图上标记出相关的位置。
*/
阅读全文