公众号H5使用JS-SDK中的getLocation定位,移动网络下非常不准确,WiFi环境下勉强?
发布于 5 年前 作者 jiajing 1127 次浏览 来自 问答
下面是代码,出现的问题就是,当测试人员在wifi环境下获取定位是与真是定位相差一条街左右,但是在手机网络环境下定位可以跑到外省去相差太远了。
不知道怎么解决,麻烦大家给看一下是代码的问题吗,还是需要配置啥的。
getContent(){
this.$http.post('user/wechatshare', {
					url: encodeURIComponent(window.location.href.split('#')[0])
				}).then(res => {
					var that=this
					jweixin.config({
						debug: true,
						appId: res.data.appid, // 必填,公众号的唯一标识
						timestamp: res.data.timestamp, // 必填,生成签名的时间戳
						nonceStr: res.data.noncestr, // 必填,生成签名的随机串
						signature: res.data.signature, // 必填,签名
						jsApiList: [
							'getLocation',
						]
					});
					jweixin.ready(() => {
						jweixin.getLocation({
						  type: 'gcj02', // 默认为wgs84的gps坐标,如果要返回直接给openLocation用的火星坐标,可传入'gcj02'
						  success: function (res) {
						    that.form.lat = res.latitude; // 纬度,浮点数,范围为90 ~ -90
						    that.form.lng = res.longitude; // 经度,浮点数,范围为180 ~ -180。
							console.log("获取经纬度",that.form)
							that.getCurrentCity();
						  }
						});
					});
				});
			},
getCurrentCity() {
				var temp=this.form.lat+','+this.form.lng
				console.log(temp)
				this.$jsonp('https://apis.map.qq.com/ws/geocoder/v1?coord_type=5&get_poi=1&output=jsonp&poi_options=page_size=1;page_index=1' , {
					key: 'LBVBZ-YWKCO-POPWN-S2SJR-3TVMO-XWFH5',
					location:temp
				}).then((res)=>{
				var temp=res.result
				if(temp.ad_info.province=="北京市"||temp.ad_info.province=="重庆市"||temp.ad_info.province=="上海市"||temp.ad_info.province=="天京市"){
					this.locations=temp.ad_info.province+temp.ad_info.district+temp.address_reference.town.title;
					this.schools.city=temp.ad_info.province
				}else{
					this.locations=temp.ad_info.province+temp.ad_info.city+temp.ad_info.district+temp.address_reference.town.title;
					this.schools.city=temp.ad_info.city
				}
				uni.showToast({
								title:"定位成功"+this.form.lat+','+this.form.lng,
								duration:5000,
								icon:'none'
							})
				})
			},
1 回复

你好,问题未复现

回到顶部