Geo Location not works in BlackBerry - blackberry

I have developed an application using phonegap to retrieve Geo Location.
function getLoc() {
navigator.geolocation.getCurrentPosition(onSuccess, onError, { enableHighAccuracy: true });
}
// onSuccess Geolocation
function onSuccess(position) {
var locInfo = new Object();
locInfo.Latitude = position.coords.latitude;
locInfo.Longitude = position.coords.longitude;
locInfo.Altitude = position.coords.altitude;
locInfo.Accuracy = position.coords.accuracy;
locInfo.AltitudeAccuracy = position.coords.altitudeAccuracy;
locInfo.Heading = position.coords.heading;
locInfo.Speed = position.coords.speed;
alert(locInfo.Latitude + " " + locInfo.Longitude);
}
// onError Callback receives a PositionError object
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
above code is working fine in Android, iPhone and BlackBerry Simulator, but not in BlackBerry device. I'm using BlackBerry Torch for testing.
what could be the issue. pls reply.
Thanks :)

Try to set timeout for getCurrentPosition.

Related

Twilio ios Video Call issue

I have created a video call using Twilio JS 2.x Version. And using this in my both mobile app Android & iOS. On Android it is working perfectly.
But on iOS, there is an issue, when users reach the video call page, it's showing preview but as the user clicks on the Join Room button, then his/her video stops and just showing a black screen. But Audio option alone work's fine in ios APP.
Actual thing is we are converting web view in to Mobile sdk using React Native APP. But the twilio logic's has been written using Javascript. Can anyone help on this?
I am using the following logic:
$.ajax({
url: callInitiate + "?userSTAuthToken=" + token,
type: "POST",
data: {
callType: "video",
subType: "wb-video",
},
error: function () {},
success: function (data) {
identity = "user_" + userId;
roomName = meetingId;
videoToken = data.token;
console.log("Joining room '" + roomName + "'...");
if (previewTracks) {
connectOptions.tracks = previewTracks;
}
// Join the Room with the token from the server and the LocalParticipant's Tracks.
console.log("Test token : " + data.token);
Twilio.Video.connect(videoToken, connectOptions).then(
roomJoined,
function (error) {
console.log("Unable to connect to Room: " + error.name);
TV.Util.DialogIntimation(
"Notification",
"Unable to connect to Room " + error.name
);
logTwilioerror(10);
$("#maskDiv").hide();
}
);
},
});
function roomJoined(room) {
window.room = activeRoom = room;
console.log("Joined as '" + identity + "'");
addIcons();
logSessionDetails(videoToken, room.sid, room.localParticipant.sid, room.name);
// Attach LocalParticipant's Tracks, if not already attached.
var previewContainer = document.getElementById("local-media");
if (!previewContainer.querySelector("video")) {
attachTracks(getTracks(room.localParticipant), previewContainer);
}
// Attach the Tracks of the Room's Participants.
var remoteMediaContainer = document.getElementById("remote-media");
room.participants.forEach(function (participant) {
console.log("Already in Room: '" + participant.identity + "'");
participantConnected(participant, remoteMediaContainer);
});
// When a Participant joins the Room, log the event.
room.on("participantConnected", function (participant) {
console.log("Joining: '" + participant.identity + "'");
participantConnected(participant, remoteMediaContainer);
});
// When a Participant leaves the Room, detach its Tracks.
room.on("participantDisconnected", function (participant) {
console.log(
"RemoteParticipant '" + participant.identity + "' left the room"
);
detachParticipantTracks(participant);
removeName(participant);
});
// Once the LocalParticipant leaves the room, detach the Tracks of all Participants, including that of the LocalParticipant.
room.on("disconnected", function () {
console.log("Left---disconnected");
logVideoActivity(
"10841",
"Tutor side disconnected the video Successfully."
);
if (previewTracks) {
previewTracks.forEach(function (track) {
track.stop();
});
previewTracks = null;
}
detachParticipantTracks(room.localParticipant);
room.participants.forEach(detachParticipantTracks);
room.participants.forEach(removeName);
activeRoom = null;
});
}

Can't play local videos in IOS 9 with Phonegap app

I made an IOS 9 app using Phonegap 6.2.0. I need to play videos with no connection, so I download it using cordova FileTransfer plugin:
var uri = encodeURI(file.url);
var fileTransfer = new FileTransfer();
// var fileLocation = cordova.file.applicationStorageDirectory +
// '/Documents/' + file.folder + '/' + file.fileName;
var fileLocation = cordova.file.dataDirectory + file.fileName;
var deferred = $q.defer();
fileTransfer.headers = {
Connection: "close"
};
fileTransfer.download(uri, fileLocation, function(result) {
console.log("Fichero descargado: " + JSON.stringify(result));
deferred.resolve(result);
}, function(error) {
deferred.reject(error);
});
return deferred.promise;
I've tried different file locations to download it (https://cordova.apache.org/docs/en/latest/reference/cordova-plugin-file/)
Then, I return the file path using resolveLocalFileSystemURL:
var deferred = $q.defer();
var nativePath = cordova.file.dataDirectory + nombreFichero + "." + extension;
resolveLocalFileSystemURL(nativePath, function(entry) {
//deferred.resolve(entry.nativeURL);
console.log("Fichero native: " + entry.toNativeURL());
console.log("Fichero fullPath: " + entry.fullPath);
console.log("Fichero toUrl: " + entry.toURL());
console.log("Fichero toInternalURL: " + entry.toInternalURL());
deferred.resolve(entry.toURL());
}, function(error) {
console.log("Error al leer el fichero: " + JSON.stringify(error));
deferred.reject(error);
});
return deferred.promise;
I've tried all file formats but none of them worked:
cdvfile://localhost/library-nosync/97a7d50f-05d1-4642-96e9-b0b26ea41897.mp4
file:///var/mobile/Containers/Data/Application/6CD24D7A-7A39-4AFE-A43B-788FCDFCEB5A/Library/NoCloud/a88d38b8-85e8-4b9b-b57e-a8eb2731eb0d.mp4
http://localhost/library-nosync/97a7d50f-05d1-4642-96e9-b0b26ea41897.mp4 and using port 12344
Some formats do nothing, some show the button play strikethrough...
In all answers I had read they recommend to use .toNativeUrl() but it doesn't work for me...
I also tried cordova-plugin-streaming-media (I can't post more links), but it does not work (no play video, no errors...)
Any idea?
Solved.
My code works good and play videos. The problem was in the URL to download the video, it gets a string with the url and not the video (therefore download and open file method didin't throw error)
Summarizing, toUrl() works.
Thanks #Gandhi for your replies.

Geolocation Using Ionic Cordova Returning Incorrect Lat/Long Values

I am facing issue using Geolocation pluggin with Ionic and Cordova framework.
Using Visual Studio Community 2015, with Cordova CLI version :4.3.0 and added the org.apache.cordova.geolocation pluggin to VSC-2015
My controller.js
.controller('MapCtrl', function ($scope) {
function onSuccess(position) {
console.log(position.timestamp);
console.log(position.coords.latitude + " " + position.coords.longitude);
}
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
navigator.geolocation.getCurrentPosition(onSuccess, onError);
})
Added the google maps into the index.html
<script src="https://maps.googleapis.com/maps/api/js?sensor=true&v=3.exp"></script>
Added a Map to my Map.html file
<div id="map" data-tap-disabled="true" map> </div>
The problem is I always get a fixed value of Lat/Long
ie Lat = 43.465187 and Long = -80.522372
This is not my correct Geolocation in terms of Lat/Long.I need my current Geolocation in terms of Lat/Long
Please help me identity the fault.
Also I am using Ripple -Nexus (Galaxy) on Browser.
Any help is appreciated...
Thanks,
Download the Latest version of GeoLocation pluggin from https://github.com/apache/cordova-plugin-geolocation
Then inject the $cordovaGeolocation into the controller.
Code is as below:
.controller('HomeCtrl', function($scope,$cordovaGeolocation) {
$scope.getLocation = function() {
var posOptions = {timeout: 10000, enableHighAccuracy: false};
$cordovaGeolocation
.getCurrentPosition(posOptions)
.then(function (position) {
//these are your your lat long values
var lat = position.coords.latitude
var long = position.coords.longitude
}, function(err) {
// error
});
}
})
Note: The device need to be connected to internet or wifi and also need to keep the GPS location ON in the device for getting the correct Lat/Long Values.
I am not sure why you get fixed lat/long values. However to get the device's position using Ionic, the following works for me:
ionic.Platform.ready($scope.getLocation);
$scope.getLocation = function () {
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition($scope.showPosition, $scope.showError);
}
else {
console.log('Geolocation is not supported by this browser.');
}
}
$scope.showPosition = function (position) {
console.log(position.timestamp);
console.log(position.coords.latitude + ' ' + position.coords.longitude);
}
$scope.showError = function (error) {
switch (error.code) {
case error.PERMISSION_DENIED:
console.log('User denied the request for Geolocation.');
break;
case error.POSITION_UNAVAILABLE:
console.log('Location information is unavailable.');
break;
case error.TIMEOUT:
console.log('The request to get user location timed out.');
break;
case error.UNKNOWN_ERROR:
console.log('An unknown error occurred.');
break;
}
}
Note that the call to:
ionic.Platform.ready($scope.getLocation);
Is crucial, as you can only guarantee you'll get an accurate GPS fix once the device is ready/initialised.

How to upload powerpoint file to server phonegap?

Hello I Want to upload a powerpoint file using phonegap file transfer protocol to my local java server thru ios simulator, the location of the file on the phone is passed to the handleOpenURL function when the user selects to open a powerpoint with my app. The problem is that nothing is happening although im sure this method is executing??!! can anyone help please?
function handleOpenURL(url)
{
setTimeout(function() {
alert(url);
jQuery.get( "http://192.168.1.100:8080/PpServer/getnumberofslides" , function( data ) {
numberofslides=data;
alert( "Load was performed." + data );
});
fileURL = url;
function win(r) {
console.log("Code = " + r.responseCode);
console.log("Response = " + r.response);
console.log("Sent = " + r.bytesSent);
// processapplication();
}
function fail(error) {
alert("An error has occurred: Code = " + error.code);
console.log("upload error source " + error.source);
console.log("upload error target " + error.target);
}
var uri = encodeURI("http://192.168.1.100:8080/NewServerlet");
var options = new FileUploadOptions();
options.fileKey="file";
options.fileName=fileURL.substr(fileURL.lastIndexOf('/')+1);
options.mimeType="multipart/form-data";
options.httpMethod="Post"
// options.params = {"file"};
var headers={'headerParam':'file'};
// options.headers = headers;
var ft = new FileTransfer();
ft.onprogress = function(progressEvent) {
if (progressEvent.lengthComputable) {
loadingStatus.setPercentage(progressEvent.loaded / progressEvent.total);
} else {
loadingStatus.increment();
}
};
ft.upload(fileURL, uri, win, fail, options);
}, 0);
//
}

Send gps coordinates to server every minute

I'm tyring to build a PhoneGap app with jQueryMobile. In my app I need to send a users current geolocations GPS coordinates to server every 4 minute. How can I do this?
This is the code I have been using right now, but it doesn't send any data. How can i modify this to make it work?
document.addEventListener("deviceready", onDeviceReady, false);
var watchID = null;
// PhoneGap is ready
//
function onDeviceReady() {
// Update every 4 minute
var options = { maximumAge: 240000, timeout: 5000, enableHighAccuracy: true };
watchID = navigator.geolocation.watchPosition(onSuccess, onError, options);
}
// onSuccess Geolocation
//
function onSuccess(position) {
var lat = Position.coords.latitude;
var lng = Position.coords.longitude;
jQuery.ajax({
type: "POST",
url: serviceURL+"locationUpdate.php",
data: 'x='+lng+'&y='+lat,
cache: false
});
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
Instead of calling setInterval, let phonegap do that for you.
// onSuccess Callback
// This method accepts a `Position` object, which contains the current GPS coordinates
//
function onSuccess(position) {
var element = document.getElementById('geolocation');
element.innerHTML = 'Latitude: ' + position.coords.latitude + '<br />' +
'Longitude: ' + position.coords.longitude + '<br />' +
'<hr />' + element.innerHTML;
}
// onError Callback receives a PositionError object
//
function onError(error) {
alert('code: ' + error.code + '\n' +
'message: ' + error.message + '\n');
}
// Options: retrieve the location every 3 seconds
//
var watchID = navigator.geolocation.watchPosition(onSuccess, onError, { frequency: 3000 });
http://docs.phonegap.com/en/1.0.0/phonegap_geolocation_geolocation.md.html#geolocation.watchPosition

Resources