Geolocation Javascript Cordova Not Triggered - javascript

I have a mobile app built with Cordova.
On one of the button an onclick event triggers a functions supposed to alert the geolocation. I've installed Cordova geolocation API for the project with cordova plugin add cordova-plugin-geolocation from https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/#weather
Then I have the functions according to https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-geolocation/#reference
So basicaly my HTML is
<button onclick="getPOS();">CLICK_ME</button>
And my JS is
function getPOS(){
alert("ok");
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');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError, { timeout: 30000 });
}
When I launch this in my firefox browser, it asks if I want to share location. If I choose to share, it shows the location fine.
Next When I build the app with cordova, when the apk installation is complete, it says the app requires Network connection and Location ..... which is normal and it means everything is properly set.
Then what I do is enable my phones GPS and Internet connextion
PROBLEM : upon clicking the link CLICK_ME on my phone, nothing happens though GPS and internet are enabled.
After the time out is expired, I get the following error :
Code: 3
message: Timeout expired
Any idea what's wrong here ?

Add these lines to manifest file
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"></uses-permission>
It might be missing permissions for Android.
Regards.

Related

html - IE when printing more number of pages then IE became unresponsive

I print more number of pages from html in IE after first time printing that particular web page became unresponsive. I am printing this using the below code,
function printdData(content)
{
var textPopupWindow = window.open('','popup','toolbar=no,menubar=no,width=1,height=1 left=-5000');
textPopupWindow.document.open();
textPopupWindow.document.write(getPrintData(content));
textPopupWindow.document.close();
}
function getPrintData(printData)
{
return "<html moznomarginboxes mozDisallowSelectionPrint>\n" +
"<head>\n" +
"<meta http-equiv=\"X-UA-Compatible\" content=\"IE=8\" />\n" +
"<script>\n" +
"function step1() {\n" +
" setTimeout('step2()', 10);\n" +
"}\n" +
"function step2() {\n" +
" window.print();\n" +
" window.close();\n" +
"}\n" +
"</script>\n" +
"<style type=\"text/css\" media=\"print\">\n" +
"#page \n" +
"{\n" +
"size: auto;\n" +
"margin-top: 0.25in;\n" +
"margin-bottom: 0.25in;\n" +
"}\n" +
"</style>\n" +
"</head>\n" +
"<body onLoad='step1()' style=\"font-size: 12px;\">\n" +
printData +
"</body>\n" +
"</html>\n";
}
This is the code I used to print the html generated content from the web page.
The 'printData' contains the html content going to print. This problem is in IE only but it works fine in chrome and firefox.
IE Specs:
Version: IE 9
OS: Windows 7
Without seeing more details, a full autopsy of the code you've given cannot be performed. Let us know more details about the browser like the following:
IE Version
Operating System ("Windows _" I presume)
In the meantime try disabling all add-ons. That is a common efficiency drain for IE since the advent of add-ons. In addition if that does not solve what you need, try this thread: superuser forum post

Barcode Scanner Phonegap not working

I am trying to include the barcode scanner plugin for phonegap (phonegap 5.1.1) and I can't make it work (https://github.com/phonegap/phonegap-plugin-barcodescanner)
First of all, I installed the plugin running:
phonegap plugin add phonegap-plugin-barcodescanner
Then I have a javascript function:
function leerBarCode(){
//navigator.notification.alert("LLega a leerBarCode", alertDismissed, "Mensaje", "OK");
cordova.plugins.barcodeScanner.scan(function (result) {
alert("We got a barcode\n" +
"Result: " + result.text + "\n" +
"Format: " + result.format + "\n" +
"Cancelled: " + result.cancelled);
}, function (error) {
alert("Scanning failed: " + error);
});
}
When I click over a button that calls to this function, it doesn't launch the camera. Please, can you help me?

Phantomjs does not open web page

I have started testing campus2020 site with casperjs (1.1.0-beta3) + phantomjs (1.9.8). And faced with the problem that site is not opening but instead tests just freeze. I have taken script example from phantomjs site:
var page = require('webpage').create();
page.open('http://informatik.uni-leipzig.de/campus2020', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});
It worked fine on other sites. I have tested opening the campus2020 site with phantomjs on several environments: win 7, Ubuntu 14.04, with ghostdriver and java selenium webdriver, with phantomjs which is run in selenium grid on RHEL 6.6. All this options failed. I have tried to add userAgent option and setTimeout. Nothing changed. Also I tried to open this site using testing framework based on selenium webdriver which used phantomjs but it worked in the same way - phantomjs initialized and then freezes. Any ideas how could be this issue solved?
Update
Now my code looks like these:
var page = require('webpage').create();
console.log("Page is going to be opened...")
page.open('http://informatik.uni-leipzig.de/campus2020/', function(status) {
console.log("Status: " + status);
if(status === "success") {
page.render('example.png');
}
phantom.exit();
});
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg + ' (from line #' + lineNum + ' in "' + sourceId + '")');
};
page.onError = function (msg, trace) {
console.log(msg);
trace.forEach(function(item) {
console.log(' ', item.file, ':', item.line);
})
}
page.onResourceError = function(resourceError) {
console.log('Unable to load resource (#' + resourceError.id + 'URL:' + resourceError.url + ')');
console.log('Error code: ' + resourceError.errorCode + '. Description: ' + resourceError.errorString);
};
page.onResourceTimeout = function(request) {
console.log('Response (#' + request.id + '): ' + JSON.stringify(request));
};
And no errors are shown.
I don't know why there is this issue, but you can update to PhantomJS 2 and it will work. There are not yet binaries for Linux, so you will need to build it yourself.
You will also need to update your CasperJS version, because the 1.1-beta3 doesn't support PhantomJS 2, but the master branch on GitHub does.
phantomjs --debug=true phantom_test.js

email message with changing information

I am trying to create email templates just using an html file. This file will display a list of mailto links that, when clicked, will open a template with message. I got it working for the most part but some of these templates use prompts to add information to the message before creating it. The problem is that it doesn't seem to work right. Here is my code.
function sendReport(emailName, addresseList){
document.writeln('<a onClick="setPrompt(this,\'' + addresseList + '\')" href="mailto:' + addresseList + '?subject=' + 'Report' + '&body=' + 'Here is the report.' + '">' + emailName + '</a><br />');
}
function setPrompt(obj, addresseList){
var reportName = prompt("Report name","");
obj.attr('href', ='mailto:' + addresseList + '?subject=' + reportName + '&body=' + "Here is the report."); //<-- this is the line that is giving me trouble.
}
You have a typo in the last line and there is no .attr() built in function in Javascript. This should fix it:
obj.setAttribute('href', 'mailto:' + addresseList + '?subject=' + reportName + '&body=' + "Here is the report.");

Internet Explorer open outlook appointment javascript

Go figure, I am having issues with IE and was hoping someone might be able to help....
I have a site where visitors will come and sign up for a specific meeting and then I want to be able to generate an appointment for the calendar of their choice; the choices are gmail, yahoo, and outlook. The gmail and yahoo appointments are generated as expected in all browsers, but the outlook appointments work in every browser except IE. Instead of throwing a file save dialog, IE opens a new window and attempts to navigate the url.
I am using the iCalendar jquery library that I modified a bit and building the ics markup in javascript, like this
//build ics markup
var event = makeAppointment(settings);
//render ics markup as outlook appointment
window.open("data:text/calendar;charset=utf8," + escape(event));
function makeAppointment()
{
return 'BEGIN:VCALENDAR\n' +
'VERSION:2.0\n' +
'PRODID:jquery.icalendar\n' +
'METHOD:PUBLISH\n' +
'BEGIN:VEVENT\n' +
'UID:' + new Date().getTime() + '#' +
(window.location.href.replace(/^[^\/]*\/\/([^\/]*)\/.*$/, '$1') || 'localhost') + '\n' +
'DTSTAMP:' + $.icalendar.formatDateTime(new Date()) + '\n' +
(event.url ? limit75('URL:' + event.url) + '\n' : '') +
(event.contact ? limit75('MAILTO:' + event.contact) + '\n' : '') +
limit75('TITLE:' + event.title) + '\n' +
'DTSTART:' + $.icalendar.formatDateTime(event.start) + '\n' +
'DTEND:' + $.icalendar.formatDateTime(event.end) + '\n' +
(event.summary ? limit75('SUMMARY:' + event.summary) + '\n' : '') +
(event.description ? limit75('DESCRIPTION:' + event.description) + '\n' : '') +
(event.location ? limit75('LOCATION:' + event.location) + '\n' : '') +
(event.recurrence ? makeRecurrence(event.recurrence) + '\n' : '') +
'END:VEVENT\n' +
'END:VCALENDAR';
}
You can get the file save dialog to work in IE by adding a "Content-Disposition: attachment" response header. However, this must happen on the server and cannot happen in client-side scripting, since JavaScript cannot modify header information.
See this answer for related details.

Categories

Resources