cordovaGeolocation error: position retrieval timed out - angularjs

Hello I want to implement some geolocation features in my app.
So I implemented a watchposition function like this:
.controller('NavigationCtrl', function ($scope,$cordovaGeolocation) {
var watchOptions = {
frequency : 1000,
timeout : 20*1000,
enableHighAccuracy: false // may cause errors if true
};
var watch = $cordovaGeolocation.watchPosition(watchOptions);
watch.then(
null,
function(err) {
alert("WatchPosition failed: "+JSON.stringify(err));
},
function(position) {
$scope.position = position;
}
);
})
Well in the first call of the template I get a geolocation but than after 20 seconds I get an error:
code:3, message:'Position retrieval timed out'
I'm testing the app on a iPhone 5s iOS 8.3.
I googled around and found out that cordova 3.1 has some errors with geolocations so I choose to use the html api for geolocations like here:
https://developer.mozilla.org/en-US/docs/Web/API/Geolocation/Using_geolocation
but it didn't show me anything in my ionic-framework app.
What am I missing?
I'm using cordova 4.3.0 and ionic 1.3.19.

I found out that I have to put the code in a $ionicPlatform.ready function to be sure that the device is ready before it start geolocating. Now it working fine.

Related

GET https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/res/locales/es-419/allstrings.json net::ERR_ABORTED 404 (Not Found)

I'm using Autodesk Forge APIs for developing a web application and everything is working fine, but a new message has appeared in the browser console while developing.
GET https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/res/locales/es-419/allstrings.json net::ERR_ABORTED 404 (Not Found)
browser console message
browser console message
browser console message
This is how I include Forge in my project:
src="https://developer.api.autodesk.com/modelderivative/v2/viewers/7.*/viewer3D.min.js"
I've looked up the Changelog of Autodesk Forge and I've found a new change with the latest version.
7.68
Release Date: 5/19/2022
Changed
Update default endpoint from https://developer[-env].api.autodesk.com to https://cdn[-env].derivative.autodesk.com
I don't know if the error is produced because of this change or what is producing it.
Could someone help me?
Thank you very much.
EDIT:
var options = {
env: 'AutodeskProduction2',
api: 'streamingV2',
getAccessToken: getForgeToken,
};
Autodesk.Viewing.Initializer(options, function() {
var htmlViewer = document.getElementById(ventana.items.keys[0]);
var viewerConfig;
viewerConfig = {
extensions: [
'Autodesk.DefaultTools.NavTools',
'Autodesk.Viewing.ZoomWindow',
'ExtensionToolbarHerramientas',
'ExtensionImprimir',
'ExtensionCommand'
]
};
var childNodes = document.getElementById(ventana.items.keys[0]);
childNodes.innerHTML = "";
viewerApp = new Autodesk.Viewing.GuiViewer3D(htmlViewer, viewerConfig);
var strtedCode = viewerApp.start();
if (strtedCode > 0) {
console.error('Failed to create a Viewer: WebGL not supported');
return;
}
console.log('Initialization complete, loading a model next...');
var documentId = 'urn:' + visorForge.urn;
Autodesk.Viewing.Document.load(documentId, onForgeDocumentLoadSuccess, onForgeDocumentLoadFailure);
});
I'm not sure if you already resolved this but I ran into this problem recently. After including language: 'en' (or 'es' in your case) in the InitOptions this error went away.
var options = {
env: 'AutodeskProduction2',
api: 'streamingV2',
getAccessToken: getForgeToken,
language: 'en'
};

Set retry with dropzone-react-component when upload fails

In my project I'm using React-Dropzone-Component (https://github.com/felixrieseberg/React-Dropzone-Component) based on Dropzone.js.
I'm using this component because I'm developing a SharePoint webpart and there is already an example based on this solution on Microsoft PnP GitHub repository.
Anyway, the upload is working fine, but sometimes, mainly when I keep a web page opened for a couple of minutes doing nothing, I receive an error trying to upload new files. I retry an upload and it fails returning Server responded with (0) code error. I also see on Google Chrome console an ERR_CONNECTION_RESET error. If I try to upload 5 files in second instance, I get error on first 2-3 and then the remaining files works fine. Weird.
I've already investigated my network, but there are no failures. I've also tried with 3 different networks and I've received the same error.
I've also updated the component with the latest Dropzone.js (5.7.2).
This is my code:
let componentConfig = {
iconFiletypes: this.props.fileTypes.split(','),
showFiletypeIcon: true,
postUrl: _context.pageContext.web.absoluteUrl,
autoProcessQueue: true
};
var djsConfig = {
headers: {
"X-RequestDigest": digest1
},
addRemoveLinks:false
};
let myDropzone;
let eventHandlers = {
// This one receives the dropzone object as the first parameter
// and can be used to additional work with the dropzone.js
// object
init: function(dz){
myDropzone=dz;
},
sending: async function (file, xhr) {
var fileName = file.name;
fileName = fileName.replace(/[&\/\\#,+()$~%='":*?<>{}]/g, "");
if (file.size <= 10485760) {
// small upload
await web.getFolderByServerRelativeUrl("/test/"+_listName).files.add(fileName, file, true).then(_ => console.log("Ok!"));
} else {
// large upload
await web.getFolderByServerRelativeUrl("/test/"+_listName).files.addChunked(fileName, file, data => {}, true).then(_ => console.log("Ok!"));
}
},
error:function(file,error,xhr){
file.status = myDropzone.ADDED;
myDropzone.removeFile(file);
myDropzone.enqueueFile(file);
}
};
<DropzoneComponent eventHandlers={eventHandlers} djsConfig={djsConfig} config={componentConfig}>
<div className="dz-message icon ion-upload">Drop files here to upload</div>
</DropzoneComponent>
If I can't prevent this ERR_CONNECTION_RESET error, I would like to set up an automatic retry for these files. The code I've posted above is not working fine or it returns "Uncaught Error: This file can't be queued because it has already been processed or was rejected.".
Is there a solution or a good way to set up a retry?

PubNub AngularJS error in push config: 'Pubnub.push.addChannels' is undefined

Using PubNub and trying to setup push for ios (apns) per their docs.
The following generates the error:
var initPubnubPush = function(token) {
Pubnub.push.addChannels(
{
channels: ['my_first_channel'],
device: token,
pushGateway: 'apns' // apns, gcm, mpns
},
function(status) {
if (status.error) {
console.log("operation failed w/ error:", status);
} else {
console.log("operation done!")
}
}
);
}
I have their publish/subscribe working on the channel my_first_channel and push should work when the app is in background. The token is valid and is returned from
pushNotification.register(
tokenHandler,
errorHandler,
{
'badge':'true',
'sound':'true',
'alert':'true',
'ecb':'onNotificationAPN'
}
);
function tokenHandler(token) {
// This is a device token you will need later to send a push
// Store this to PubNub to make your life easier :-)
initPubnubPush(token);
}
The complete error in Safari console while running on real iPhone device:
Error in Success callbackId: PushPlugin63370093 : TypeError:
Pubnub.push.addChannels is not a function.
(In 'Pubnub.push.addChannels', 'Pubnub.push.addChannels' is undefined)
Can't find anything in google for this error.
Turns out there is a bug in the PubNub Angular library and that method push.addChannels is not properly delegated.

SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd. index.html

I am using Visual studio 2015 and ionic and i have been able to build for windows phone 8.1. I created a login page that is to query a php on a different server but i get a problem like this SCRIPT7002: XMLHttpRequest: Network Error 0x2efd, Could not complete the operation due to error 00002efd.
index.html
error. My code trying to make a request is
var login = function(name, pw) {
return $q(function(resolve, reject) {
$http.post('http://192.167.180.1//logn/sear.php',{ 'pin': pw }).then(
function(result) {
// No result here..
var re=result.data.split(",");
console.log(re[3]);
if ((re[0] == 0 )) {
// Make a request and receive your auth token from your server
storeUserCredentials(re[2]);
useCredentials(re[1]+" "+re[3]+" "+re[4]);
console.log(LOCAL_TOKEN_KEY);
resolve('Login success.');
} else if(result.data == 1) {
reject('Login Failed.');
}
}, function(err) {
// $scope.response = err.records;
console.log("error");
});
});
};
When you are facing this error while building a Win 8 Phone App, you might want to add private network capability to app manifest.
Credits for the guy who helped me out: https://sonyarouje.com/tag/network-error/
- there you'll find step-by-step instruction how to do it.
There is also another answer how to do it on SO:
WinJS.xhr: Network Error 0x2efd, Could not complete the operation due to error 00002efd

Device Orientation and Cordova

I have a problem with Device Orientation, Ionic and Cordova/ngCordova
I've already run the command:
"cordova plugin add cordova-plugin-device-orientation"
to install the device orientation plugin
It installed without problem.
Then I add the following code to my app:
.controller('MyCtrl', function ($scope,$cordovaDeviceOrientation) {
$cordovaDeviceOrientation.getCurrentHeading().then(function(result) {
var magneticHeading = result.magneticHeading;
var trueHeading = result.trueHeading;
var accuracy = result.headingAccuracy;
var timeStamp = result.timestamp;
$scope.values=magneticHeading+" "+trueHeading+" "+accuracy+" "+timeStamp;
}, function(err) {
// An error occurred
});
})
After executing cordova run android I got this error.
Cannot read property 'getCurrentHeading' of undefined.
I tested this code on the browser, Genymotion or Samsung Galaxy Tab 4, but always I got the same error.
What am I doing wrong?
There's two things you need to know:
First: This kind of plugin, like device orientation, need to be tested in real devices once it use a accelerometer hardware to work.
Second: You need to use the DeviceReady EventListner to use the plugins, so, you need to do something like this:
document.addEventListener("deviceready", function () {
$cordovaDeviceOrientation.getCurrentHeading().then(function(result) {
var magneticHeading = result.magneticHeading;
var trueHeading = result.trueHeading;
var accuracy = result.headingAccuracy;
var timeStamp = result.timestamp;
$scope.values=magneticHeading+" "+trueHeading+" "+accuracy+" "+timeStamp;
}, function(err) {
// An error occurred
});
}, false);
If you want, there's a seed for angularjs + cordova + angular-material here:
https://github.com/marioaleogolsat/cordova-angular-angularMaterial-seed
Your device may not have a compass.

Resources