ilkkatakayama opened a new issue, #252:
URL: https://github.com/apache/cordova-plugin-geolocation/issues/252
<!--
Please have a look at the issue templates you get when you click "New issue"
in the GitHub UI.
We very much prefer issues created by using one of these templates.
-->
### Issue Type
<!-- Please check the boxes by putting an x in the [ ] like so: [x] -->
- [ ] Bug Report
- [ ] Feature Request
- [x] Support Question
## Description
I have been trying to get cordova-plugin-geolocation to work on android. The
permissions to use geolocation were not being asked when the program was run.
One has to use cordova.plugins.diagnostic plugin to ask for those
permissions. Here is an example how to do it. Sorry for messy post, I am just
exhausted and don't want others to be as lost as I was
CLI
[code]cordova plugin add cordova.plugins.diagnostic[/code]
index.html
[code]
<!DOCTYPE html>
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<html>
<head>
<meta charset="utf-8">
<!--
Customize this policy to fit your own app's needs. For more
guidance, please refer to the docs:
https://cordova.apache.org/docs/en/latest/
Some notes:
* https://ssl.gstatic.com is required only on Android and is
needed for TalkBack to function properly
* Disables use of inline scripts in order to mitigate risk of
XSS vulnerabilities. To change this:
* Enable inline JS: add 'unsafe-inline' to default-src
-->
<meta http-equiv="Content-Security-Policy" content="default-src
'self' data: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self'
'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="initial-scale=1, width=device-width,
viewport-fit=cover">
<meta name="color-scheme" content="light dark">
<link rel="stylesheet" href="css/index.css">
<title>Hello World</title>
</head>
<body>
<div class="app">
<h1 id="myButton">Apache Cordova CLICK ME</h1>
<div id="deviceready" class="blink">
<p class="event listening">Connecting to Device</p>
<p class="event received">Device is Ready</p>
</div>
</div>
<script src="cordova.js"></script>
<script src="js/script.js"></script>
<script src="js/index.js"></script>
</body>
</html>
[/code]
script.js
[code]
document.getElementById("myButton").addEventListener("click", myFunction);
var onSuccess = function(position) {
alert('Latitude: ' + position.coords.latitude + '\n' +
'Longitude: ' + position.coords.longitude +
'\n' +
'Altitude: ' + position.coords.altitude +
'\n' +
'Accuracy: ' + position.coords.accuracy +
'\n' +
'Altitude Accuracy: ' + position.coords.altitudeAccuracy +
'\n' +
'Heading: ' + position.coords.heading +
'\n' +
'Speed: ' + position.coords.speed +
'\n' +
'Timestamp: ' + position.timestamp +
'\n');
};
// onError Callback receives a PositionError object
//
function onError(error) {
alert( 'code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
options = {
maximumAge: 0,
timeout: 60000,
enableHighAccuracy: true
}
function myFunction(){
cordova.plugins.diagnostic.requestRuntimePermissions(function(statuses){
for (var permission in statuses){
switch(statuses[permission]){
case
cordova.plugins.diagnostic.permissionStatus.GRANTED:
alert("Permission granted to use
"+permission);
break;
case
cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
alert("Permission to use "+permission+"
has not been requested yet");
break;
case
cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
alert("Permission denied to use
"+permission+" - ask again?");
break;
case
cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
alert("Permission permanently denied to
use "+permission+" - guess we won't be using it then!");
break;
}
}
}, function(error){
console.error("The following error occurred: "+error);
},[
cordova.plugins.diagnostic.permission.ACCESS_FINE_LOCATION,
cordova.plugins.diagnostic.permission.ACCESS_COARSE_LOCATION
]);
var watchId = navigator.geolocation.watchPosition(onSuccess,
onError,
options);
}
[/code]
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]