微信小程序--实现地图定位---获取经纬度

(1)

(2)

(3)

html:

html 复制代码
	<view class="titleTwo" style="border: none;">
				<view class="fontSize30 invoiceTile">企业地址</view>
				<view class="invoiceRight" bind:tap="tapChooseAddress"  data-maptype="2">
					<view class="inputRight fontSize30" style="{{detailedAddress=='请选择企业地址'?'color:#777;':''}} height: auto;" >
						{{detailedAddress || '请选择企业地址'}}
					</view>
				</view>
				<view class="clearBoth"></view>
			</view>

js:

javascript 复制代码
	tapChooseAddress(e) {
		let that = this;
		let maptype = e.currentTarget.dataset.maptype;
		// 地图选点
		wx.chooseLocation({
		  success: function (res) {
		    if(maptype == "1"){
		      that.setData({
		        detailedAddress: res.name,
		        xxdzLongitude: res.longitude,
		        xxdzLatitude: res.latitude,
		      });
		    }else{
		      that.setData({
		        detailedAddress: res.name,
		        xxdzLongitude: res.longitude,//经度
		        xxdzLatitude: res.latitude,//纬度
		      });
		      
		    }
		    
		  },
		  fail: function (err) {
		    console.log(err)
		    wx.showToast({
		      title: '地图位置获取错误',
		      icon: "none"
		    })
		  }
		})
	},
	// res.longitude,//经度
  //latitude,//纬度

app.json:

javascript 复制代码
   "requiredPrivateInfos": [
      "getLocation",
      "chooseLocation"
    ],
    "permission": {
      "scope.userLocation": {
        "desc": "获取用户位置信息用于填写收货地址"
		}
      },
相关推荐
客场消音器9 小时前
如何使用codex进行UI重构,让AI开发的前端页面不再千篇一律
前端·后端·微信小程序
打瞌睡的朱尤13 小时前
微信小程序126~160
微信小程序·小程序
腾讯云云开发14 小时前
小程序成长计划正式接入Hy3 preview
微信小程序
bruce5411015 小时前
讲讲 RTMate (WebSocket as A Service)中的消息的发布订阅机制
后端·微信小程序
我是伪码农16 小时前
小程序50-75
小程序
ZC跨境爬虫16 小时前
模块化烹饪小程序开发日记 Day2:全局配置与 tabBar 实现
java·前端·javascript·微信小程序·html·notepad++
好赞科技17 小时前
2026年医院预约小程序三大精选:解锁智慧医疗新体验
大数据·微信小程序
ZC跨境爬虫17 小时前
模块化烹饪小程序开发日记 Day1:项目初始化与模块化目录设计
前端·javascript·ui·微信小程序·音视频
double_eggm1 天前
5.微信小程序
小程序
梦想的颜色1 天前
2026最新Claude Code 规范文件 CLAUDE.md 全面解析与超全模板
人工智能·小程序