我想在用户单击按钮时获取当前用户位置
我也尝试过 geoLocation.getCurrentLocation() 这个
但它不起作用 还有其他选择可以实现这一目标吗?
TeamsJS 库提供了 getLocation API,您可以使用它来获取用户的当前位置。
microsoftTeams.initialize();
microsoftTeams.location.getLocation((err, location) => {
if (err) {
console.error('Error getting location: ' + err);
} else {
console.log('Location: ' + JSON.stringify(location));
}
});
位置在回调函数中以 Location 对象的形式返回,其中包含用户位置的纬度和经度。
此外,您还需要更新应用程序的清单文件以包含具有地理位置权限的 devicePermissions 字段。
{
"devicePermissions": ["geolocation"]
}
示例参考:https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/app-checkin-location