Identify user's location and include it in the response sent to the my app on MS Teams

125 Views Asked by At

To find the location of the user, I wrote the below code:

geoLocation.getCurrentLocation() .then((res) => {
console.log({ "Execute getCurrentLocation": res }); }) .catch((error) => { console.log({ "error while Execute getCurrentLocation ": error }); });

but I get the following error 'one or more provided argument is invalid' when the api gets called. This error is also mentioned on the official site of Microsoft (Error code - 4000). can you help me to resolving this error

1

There are 1 best solutions below

5
On

The TeamsJS library provides getLocation API that you can use to fetch the current location of the user.

microsoftTeams.initialize();
microsoftTeams.location.getLocation((err, location) => {
    if (err) {
        console.error('Error getting location: ' + err);
    } else {
        console.log('Location: ' + JSON.stringify(location));
    }
});

The location is returned in the callback function as a Location object, which contains the latitude and longitude of the user's location.

Also, you need to update your app's manifest file to include the devicePermissions field with the geolocation permission.

{
    "devicePermissions": ["geolocation"]
}

Sample Ref: https://github.com/OfficeDev/Microsoft-Teams-Samples/tree/main/samples/app-checkin-location