Solve the problem that the ByteDance applet cannot obtain the current user location (positioning)

The ByteDance applet cannot obtain the current user location (positioning)

The ByteDance applet cannot obtain the current user location (positioning)

I have always obtained the location of Beijing by using the method of the ByteDance developer documentation, but my location is not Beijing. The logic of the method is correct, and the preview and ByteDance developer tools show the wrong location . When I was puzzled, I consulted their customer service, and the answer I got was that real machine debugging is needed to obtain the current user location . But only to the city. (When I couldn’t apply for high-precision positioning permissions, I thought of using Tencent Maps to solve it. Also using Tencent Maps requires real machine debugging to display normally)

Byte beating realizes positioning

If your project does not require high-precision positioning, then this is fine. If high-precision positioning is required but the current applet cannot apply for high-precision positioning, you can continue to look down and use Tencent Maps to obtain high-precision positioning.

The print results of the ByteDance developer tool are as follows:
insert image description here
the real device debugging can get the "city" where the user is located, and the printing results of the mobile phone real device debugging are as follows:
insert image description here

code show as below:

tt.getLocation({
    
    
	success(res) {
    
    
		console.log("getLocation",res);
	},
	fail(res) {
    
    
		console.log("getLocation调用失败", res);
	},
});

Tencent Maps achieves high-precision positioning

The printed results of ByteDance developer tools are as follows:
insert image description here

The printing results of the mobile phone real machine debugging are as follows:
insert image description here
the code is as follows:

Write the following code for the interface that needs to get the location:

import {
    
     addressdata } from "@/common/list.js"

....

mounted() {
    
    
	this.addRess()
},
methods: {
    
    
    .......
	addRess() {
    
    
		addressdata().then((res) => {
    
    
			console.log('腾讯地图:',res.result)
			//拿到“区”
			//this.select = res.result.address_component.district 
		})
		.catch((err) => {
    
    
			//获取失败就在页面显示“位置”
			//this.select = '位置'
		})
	},
	......

Create a new list.js under common and write the following code:

var QQMapWX = require('../newSDK/qqmap-wx-jssdk.js')
var qqmapsdk;

var addressdata=function(){
    
    
	return new Promise((resolve,reject)=>{
    
    
		qqmapsdk=new QQMapWX({
    
    
			key:'你的腾讯地图key'
		});
		qqmapsdk.reverseGeocoder({
    
    
			success:(res)=>{
    
    
				resolve(res)
			},
			fail:(err)=>{
    
    
				reject(err)
			}
		})
	})
}

export {
    
    addressdata}

qqmap-wx-jssdk.js can be downloaded from the official website, the address is https://lbs.qq.com/miniProgram/jsSdk/jsSdkGuide/jsSdkOverview
insert image description here
In addition: find the manifest.json file in the root directory of the uniapp project, and configure it in the small Program-specific related here, as shown below:

        "permission" : {
    
    
            "scope.userLocation" : {
    
    
                "desc" : "你的位置信息将用于小程序接口的效果展示"
            }
        },
		"requiredPrivateInfos" : [ "getLocation" ]

insert image description here

Guess you like

Origin blog.csdn.net/qq_51463650/article/details/128812036