Oct 20 2020 05:24 PM - edited Oct 20 2020 05:31 PM
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:
"devicePermissions": [
"geolocation"
],
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?
Oct 21 2020 10:52 PM
@karamem0 Are you getting the allow location access pop up for teams desktop?
Oct 21 2020 11:23 PM
Oct 28 2020 04:42 AM
@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>