Forum Discussion
karamem0
Oct 21, 2020Brass Contributor
navigator.geolocation.getCurrentPosition() failed with Teams desktop app
I want to get login user's location information in Teams custom app, but JavaScript navigator.geolocation.getCurrentPosition() function failed when using Teams desktop app. (succeeded with Teams web app)
Teams desktop app version is 1.3.00.26064.
This is what all I did:
- Create new app with yo teams.
- Edit manifest file to allow to use geolocation.
"devicePermissions": [
"geolocation"
],
- Add the code below in componentWillMount function.
navigator.geolocation.getCurrentPosition(
(args) => {
this.setState({
latitude: args.coords.latitude,
longitude: args.coords.longitude
});
},
(err) => {
window.alert(err.message);
});
The result is:
How can I fix the problem?
3 Replies
Sort By
- Trinetra-MSFT
Microsoft
karamem0 Are you getting the allow location access pop up for teams desktop?
- karamem0Brass ContributorYes, I allowed the location access.
- Trinetra-MSFT
Microsoft
karamem0 , Could you please try this code?
@{ Layout = null;} @{ ViewBag.Title = "View"; } <script> var x = document.getElementById("demo"); function showPosition() { if (navigator.geolocation) { navigator.permissions.query({name:'geolocation'}).then(function(result) { if (result.state == 'granted') { // Access granted navigator.geolocation.getCurrentPosition(function (position) { var positionInfo = "Your current position is (" + "Latitude: " + position.coords.latitude + ", " + "Longitude: " + position.coords.longitude + ")"; document.getElementById("result").innerHTML = positionInfo; }, function (error) { console.log(error); } ); } else if (result.state == 'prompt') { // Access has not been granted console.log('Please prompty'); } }); } else { alert("Sorry, your browser does not support HTML5 geolocation."); } } </script> <html> <body> <p>Click on the Button to give Access to Your Location</p> <button onclick="showPosition()">Get Location</button> <p id="demo"></p> <div id="result"> hi </div> </body> </html>