authorizationCallback:function(done) { // 注意这里不能 async
done("eyJraWQiOiI3OVNYVEdIOU45IiwidHlwIjoiSldUIiwiYWxnIjoiRVMyNTYifQ.eyJpc3MiOiIzSzQ4UEE2MjRNIiwiaWF0IjoxNzU1ODAwMDAyLCJleHAiOjE3NTY0NTA3OTl9.qUD9RUV7oC6LAo1KmpDCst-CUyEvz1Lbk5ZPt4E3E0z0q_lFoES8YsJGdSc4_UV405XyCaBfyFNBP-BlKZzQew")
},
language: "zh-CN",
});
// 使用的方法
async function getCurrentLocation() {
if (!navigator.geolocation) {
error.value = "您的浏览器不支持地理定位";
return;
}
try {
await mapTokenManager.initializeMapKit();
map = new (window as any).mapkit.Map(mapContainer.value);
} catch (err) {
error.value = "地图初始化失败";
console.error(err);
}
isLoading.value = true;
error.value = "";
navigator.geolocation.getCurrentPosition(
(position) => {
currentLocation.value = {
latitude: position.coords.latitude,
longitude: position.coords.longitude,
accuracy: position.coords.accuracy,
timestamp: position.timestamp
};
// 在地图上显示位置
if (map) {
const coord = new (window as any).mapkit.Coordinate(
position.coords.latitude,
position.coords.longitude
);
map.setCenterAnimated(coord);
// 添加标记
const annotation = new (window as any).mapkit.Annotation(coord, {
title: "当前位置",
subtitle: `${position.coords.latitude.toFixed(6)}, ${position.coords.longitude.toFixed(6)}`
});
map.addAnnotation(annotation);
}
isLoading.value = false;
},
(err) => {
error.value = `定位失败: ${err.message}`;
isLoading.value = false;
},
{
enableHighAccuracy: true,
timeout: 10000,
maximumAge: 60000
}
);
}
Hello, as shown above, I generated a test token. In the code, I initialized it through mapkit.init, and then it reported the 401 error shown in the screenshot. This is the token created directly in the maps service on our website without background processing.
Topic:
App & System Services
SubTopic:
Maps & Location