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

(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": "获取用户位置信息用于填写收货地址"
		}
      },
相关推荐
海兰10 小时前
【小程序】基于 AI 大语言模型驱动的中国古典诗词 Web 应用详细设计指南
人工智能·语言模型·小程序
凌奕12 小时前
微信小程序接入微信 AI:让用户"说一句话"就能下单
微信·微信小程序·agent
倒流时光三十年17 小时前
第十八章 搜索历史保存功能实现记录
spring boot·微信小程序
倒流时光三十年17 小时前
第十七章 投票页面增加搜索功能
spring boot·微信小程序
博客zhu虎康19 小时前
小程序:UGC自定义发布内容接入微信公众平台内容安全API(imgSecCheck、msgSecCheck、mediaCheckAsync)
安全·小程序·微信公众平台
静Yu20 小时前
我用Codex开发的第一个朋友圈九宫格素材小程序上线啦
微信小程序·小程序·云开发
kyriewen2 天前
一个人+Cursor,7天上线付费小程序:第1天我就想放弃了
前端·微信小程序·cursor
暗不需求2 天前
从路虎汽车小程序看微信小程序开发的最佳实践
前端·javascript·微信小程序
博客zhu虎康2 天前
小程序:解决小程序发布上线后无分享功能
小程序
tuanyuan99o2 天前
2026商城小程序的安全怎么保障?防止黑客攻击和数据泄露
安全·小程序