• uniapp 高德地图与百度地图精准定位,高德地图定位报错


    目前我这边测试发现的问题
    UNIAPP 获取定位的代码

    在这里插入代码片
    data的参数
    data() {
    			return {
    				id: 0, // 使用 marker点击事件 需要填写id
    				title: 'map',
    				latitude: 39.909,
    				longitude: 116.39742,
    				covers: [{
    					latitude: 39.909,
    					longitude: 116.39742,
    					width: 50,
    					height: 50,
    					iconPath: '../../static/drdingwei.png'
    				}]
    			}
    		},
    methods: 里面的方法
    适用于百度地图精准定位    
    getLocation() {
    				const that = this;
    
    				uni.getLocation({
    					type: 'gcj02', // 返回可以用于uni.openLocation的经纬度,默认为wgs84的gps坐标
    					altitude: true,  
    					success: (res) => {
    						console.log('当前位置的经度:' + res.longitude);
    						console.log('当前位置的纬度:' + res.latitude);
    						that.latitude = res.latitude
    						that.longitude = res.longitude
    						that.covers[0].latitude = res.latitude
    						that.covers[0].longitude = res.longitude
    					},
    					fail: (err) => {
    						console.error('获取位置失败:', err);
    					}
    				});
    
    			},
    		GPS定位  适用于高德
    			getLocationa() {
    				const that = this;
    				uni.getLocation({
    					type: 'wgs84', // 返回可以用于uni.openLocation的经纬度,默认为wgs84的gps坐标
    					success: (res) => {
    						console.log('当前位置的经度:' + res.longitude);
    						console.log('当前位置的纬度:' + res.latitude);
    						that.latitude = res.latitude
    						that.longitude = res.longitude
    						that.covers[0].latitude = res.latitude
    						that.covers[0].longitude = res.longitude
    					},
    					fail: (err) => {
    						console.error('获取位置失败:', err);
    					}
    				});
    			}
    
    • 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

    一个是国标gcj02 一个是GPS
    目前发现的问题 gcj02虽然精准定位 但是 高德地图使用 多点几次 就会报错 KEY错误7
    百度地图不会出现问题

    wgs84 定位不是很准确 有偏差 高德地图随意不会报错 百度地图反应慢

    高德地图 key值在创建的时候 必须包名和SHA1值一致 不然获取不了定位

  • 相关阅读:
    PyTorch 1.13 正式发布:CUDA 升级、集成多个库、M1 芯片支持
    MySQL的基本操作(超详细)
    Java中的InetAddress类
    Linux下NFS共享存储安装详细步骤
    揭秘RLHF;可商用开源LLM列表;领域编译器的前世今生
    解决ubuntu更新内核后,NVIDIA显卡失效问题
    2024年软考重大改革
    Vue-CLI项目搭建
    Java面向对象(基础)--方法应用
    OSPF —— OSPF邻居状态机(工作机制 )
  • 原文地址:https://blog.csdn.net/qq_45499633/article/details/139204185