识别用户的位置并将其包含在发送到 MS Teams 上我的应用程序的响应中

问题描述 投票:0回答:1

我想在用户单击按钮时获取当前用户位置

我尝试过https://learn.microsoft.com/en-us/microsoftteams/platform/concepts/device-capability/location-capability?tabs=mobile%2Cteamsjs-v2#update-manifest

我也尝试过 geoLocation.getCurrentLocation() 这个

但它不起作用 还有其他选择可以实现这一目标吗?

gps microsoft-teams userlocation
1个回答
0
投票

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

© www.soinside.com 2019 - 2024. All rights reserved.