当前位置:   article > 正文

uniapp 地图篇干货_uniapp openmapapp

uniapp openmapapp

uniapp位置篇实用干货:

直接获取位置

1.需要在uniapp 的manifest.json中写入代码:

"permission" : {
            "scope.userLocation" : {
                "desc" : "医生护士上门需要地址位置信息"
            }
        },
"requiredPrivateInfos": ["getLocation", "chooseAddress", "chooseLocation"]
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6

在这里插入图片描述

2.vue页面代码:

<template>
	<view class="">
		<button @click="gotoss">获取当前位置</button>
		<button @click="aaaaaaa">获取当前位置</button>
	</view>
</template>

<script>
	export default {
		data() {
			return {
			}
		},
		methods: {
			gotoss() {
				let that = this
				wx.getLocation({
					type: 'gcj02',
					success: function(res) {
						wx.openLocation({
							latitude: res.latitude,
							longitude: res.longitude,
							scale: 18,
							success: function(res) {
								wx.chooseLocation({
									success: function(res) {
										console.log(res)
									}
								})
							}
						})
					},
					fail: function(err) {
						console.log(err)
						uni.showToast({
							title: '获取地址失败,将导致部分功能不可用',
							icon: 'none'
						});
					}
				});
			},
			  aaaaaaa() {
			    wx.getSetting({
			      success(res) {
			        console.log("vres.authSetting['scope.address']:",res.authSetting['scope.address'])
			        if (res.authSetting['scope.address']) {
			          console.log("111")
			          wx.chooseAddress({
			            success(res) {
			              console.log(res.userName)
			              console.log(res.postalCode)
			              console.log(res.provinceName)
			              console.log(res.cityName)
			              console.log(res.countyName)
			              console.log(res.detailInfo)
			              console.log(res.nationalCode)
			              console.log(res.telNumber)
			            }
			          })
			              // 用户已经同意小程序使用录音功能,后续调用 wx.startRecord 接口不会弹窗询问
			              
			        } else {
			          if (res.authSetting['scope.address'] == false) {
			            console.log("222")
			            wx.openSetting({
			              success(res) {
			                console.log(res.authSetting)
			              
			              }
			            })
			          } else {
			            console.log("eee")
			            wx.chooseAddress({
			              success(res) {
			                console.log(res.userName)
			                console.log(res.postalCode)
			                console.log(res.provinceName)
			                console.log(res.cityName)
			                console.log(res.countyName)
			                console.log(res.detailInfo)
			                console.log(res.nationalCode)
			                console.log(res.telNumber)
			              }
			            })
			          }
			        }
			      }
			    })
			  },

		}

	}
</script>

<style>
</style>

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98

直接根据已有的中文地址唤起导航

ditu(address) {
				// let address = "广东省深圳市龙华区大浪街道同胜社区华荣路联建工业园厂房2号1层"
				uni.request({
					url: 'https://restapi.amap.com/v3/geocode/geo?parameters',
					method: 'GET',
					data: {
						key: '',//自己在高德上的key
						address: address
					},
					success: (res) => {
						if (res.data.status == 1) {
							console.log('高德res', res.data.geocodes[0])
							let jd = res.data.geocodes[0].location.split(',')[0]
							let wd = res.data.geocodes[0].location.split(',')[1]
							// Map.openMap(parseFloat(wd), parseFloat(jd), address, 'gcj02')
							var that = this
							wx.openLocation({
								latitude: parseFloat(wd),
								longitude: parseFloat(jd),
								name: address,
								address: address,
							})
						}

					}
				})
			},
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/548629
推荐阅读