Phonegap geolocation.watchPosition not updating location on iPhone - ios

I am developing a phonegap application that sends the current GPS location to a server. In order to do so, we have the following code fragment:
navigator.geolocation.watchPosition(gpsTracker.onNewCoordinates, gpsTracker.onError, {
enableHighAccuracy : true,
maximumAge: 4000, //should be default, just in case
timeout: 5000
});
The callback functions take care of submitting the results. On our Android test-device this functionality is working just nicely. However when we run the same code on an iOS device it usually does nothing, except when the GPS reception is fine it will send two coordinates and then it stops.
It looks like iOS only obtains some information once, and never triggers the callback functions when there are new coordinates available.
Anyone with similar experience / solution to this problem?

I solved my issue as follows. It turns out that navigator.geolocation.watchPosition does not seem to work well on iOS. I rewrote the code using a javascript setInterval which invokes getCurrentPosition every 5 seconds instead:
navigator.geolocation.getCurrentPosition( gpsTracker.onNewCoordinates, gpsTracker.onError, {
enableHighAccuracy : true,
maximumAge: 4000, // should be default, just in case
timeout: 5000
});
Now the GPS position is correctly returned every 5 seconds.

Have a look at this:
http://groups.google.com/group/phonegap/browse_thread/thread/58f7ff98170b16c4
There is something written about geolocator.start() and stop(), preserved for iOS. Maybe this helps?
According to my experience, the GPS must be "hot" in order to deliver valid positions, i.e. it must be given enough time to connect to satellites etc. Usually, you have it "hot" only if you start watching, not if you just pick single positions. On my HTC, values gained by getCurrentPositions() have therefore turned out too unprecise (related to a near scope, e.g. within 50m). So it might be the right way to try once more to find a solution with startWatching().

Related

Swift time between run function

I am nearly new to swift Xcode and I am building an app, when the end user is near a iBeacon hi will get a local push notification.The problem I have is each time he comes near to it(if he got back and forward he will get each time he is near).
So I think to limit by time like 5 minuets of some like that.
I can not find in Swift how to limit a function to run in a time limit.(like 5 minutes)
Can some one point me in the correct direction?
Thanks for the help.
I did try to work with a timer but it did not do the job for me.
You Can create a Variable: beaconsHasBeenRecognized to turn to true when the beacon has been recognized, then the next time user goes back and forth, before triggering notification, your code should evaluate it beaconsHasBeenRecognized,its false, otherwise, if it is true, it will not trigger the notification.
Then with the timer, at the moment you set beaconsHasBeenRecognized to true, you start a timer to change beaconsHasBeenRecognized to false within the time that you want, like the 5 minutes.

How to get GCKViewVideoFrameInput working in swift?

Trying to mirror views to chromecast with the remote display API. On Android it is well documented and easy to implement. The iOS samples/docs are less complete. I understand it only supports 15 fps but that is fine for my needs.
If anyone has gotten it to work, I'd love to see a small swift sample that shows how to mirror a simple view. I'm trying to test it with this, which shows nothing on the TV and gives the device has disconnected after a few seconds. From reading the docs, that happens when you don't send anything within the first 15 secs of getting the session.
var testSession: GCKRemoteDisplaySession!
func remoteDisplayChannel(channel: GCKRemoteDisplayChannel,
didBeginSession session: GCKRemoteDisplaySession) {
// Use the session.
testSession = session
frameInput = GCKViewVideoFrameInput(session: testSession)
// any view
frameInput.view = testView
}
Make sure you are strongly referencing the session as well as the frame input. Inputs have weak references to sessions (to avoid cycles between sessions and inputs). If the session is not strongly referenced and gets destroyed, you'll see black on your remote screen followed by a timeout disconnect.

OnBeforePlay .seek doesn't work on iPad

I've scoured the web, upgraded the player, rewritten it 5 times, and now completing my 5th day of failing, and still cannot accomplish what the folks at Longtail tell me will work. (Don't get me wrong, I love 'em there, but this has me ready to jump off a bridge).
I'm simply trying to load a video that will play with Flash or iOS, and upon loading it, immediately go to a specific point in the video useing the .seek() method. Longtail tells me to use the onBeforePlay() function because iOS apparently doesn't respect the start value of the playlist. This code works like smoke with Flash, but ignores the seek in iOS.
Can ANYone assist me with this - it has become the most expensive script I've ever worked on and I have made zero progress at all. :( :( :( Also, I removed all the console functions and tried that, but with the same result.
Full code/player can be seen at http://www.tempurl.us/jw6e.html. You can see that with Flash, the video starts at 60 seconds, but on iOS, it starts at 0.
jwp = jwplayer('jwp').setup({
title: 'Single File Player', width: '720', height:'240', autostart: 'false', listbar: {position: "right",size: 400},
sources:[
{ file: 'http://media3.scctv.net/insight/mp4:nursing_4_clips_400.mp4/playlist.m3u8'},
{ file: 'rtmp://fms.scctv.net/insight/nursing_4_clips_400.mp4'}
]
}
);
jwp.onReady(function() {
// Create a playlist item of the video to play
var newItem = [
{ title: 'Title4 ACUTE_ABDO_PAIN_400',
image: 'playlistitem.png',
sources:[
{ file: 'http://media3.scctv.net/insight/mp4:ACUTE_ABDO_PAIN_400.mp4/playlist.m3u8'},
{ file: 'rtmp://fms.scctv.net/insight/ACUTE_ABDO_PAIN_400.mp4'}
]
}
];
jwp.load(newItem);
});
jwp.onBeforePlay(function() {
// This Works on PC/Mac with Flash, but does nothing on iPad/iPhone
jwp.seek(60);
});
Simply to close the question, the bottom line on this problem was that iOS will not allow autostart - period. Knowing that, all the expected events that were not behaving as expected made sense. Once the user initiates the stream with Play, everything works as expected. In our case, this is still a problem because we want to start later in the stream, but knowing that made dealing with it more manageable.
If the problem is iOS will not allow autostart - period. Knowing that,
all the expected events that were not behaving as expected made sense.
Once the user initiates the stream with Play, everything works as
expected
then you can have a play button only for tablet and ios device and on Clicking the play button,
call jwplayer().play(), this could be a work around for your problem, and after you have invoked jwplayer.play, which is only possible with the touch event, after play is triggeredother events will work.
otherwise even if you try jwplayer().play() onReady(), or autostart nothing will work because of iOs will not allow autostart as you said
I've solved this problem on iOS using onBeforePlay with seek() and play(). This work on desktop flash and IOS. Doesn't work on Android using the parameter androidhls:true
jwplayer().onBeforePlay(function() { jwplayer().seek(60); });
jwplayer().play();
As Ethan JWPlayer mentioned in comment use onPlay event. To prevent "loop buffering" as you said just use flag variable:
var isFirstStart = true,
seekValue = 60;
jwplayer().onPlay(function(){
//exit if it's no first playback start
if( !isFirstStart ) {
return;
}
jwplayer().seek(seekValue);
isFirstStart = false;
});

Returning inaccurate GPS coordinate using getCurrentPosition in Phonegap

I am developing a PhoneGap application with JQuery mobile which requires geolocation data. Currently the positions returned by getCurrentPosition() are very inaccurate, sometimes up to a mile away. It appears that the application is using googles location services to acquire the positions. Is there any way to force the application to use the GPS?
Also the first time a position is posted it often returns an old position (even though maximumAge is set to 0). Does anyone know why this could be?
I have read through the geolocation API below and have no been able to find anything.
http://dev.w3.org/geo/api/spec-source.html
A couple of things you can try is to make sure you are setting the enableHighAccuracy parameter to true in your call to getCurrentPosition.
However, most GPS chips need a bit of time before it gets you an accurate position. The better solution is to call watchPosition and wait until you get 3 to 5 results as you will find the accuracy is much better in this case. Then you can do a clearWatch and use the more accurate GPS position.
As the other writes. the getCurrentPosition is not necessarily accurate to the meter, it all depends of the GPS is active or not..
The getCurrentPossition is meant for a quick get of position for searches and initial position while the GPS get propper fix..
I normally do this:
//Initialize GPS
navigator.geolocation.getCurrentPosition(onGPSSuccess, onGPSError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });
navigator.geolocation.watchPosition(onGPSSuccess, onGPSError, { maximumAge: 3000, timeout: 5000, enableHighAccuracy: true });
Thant will get a quick posting and the the watch function will repeatedly get called for the position..
So if you expect a accurate coordinate you could check the : position.coords.accuracy for the accuracy in meters in the call back function.
This is Geolocation API, not a hardware GPS fix - so you might only get the network location.
Some stock browser also have a proximity "feature"... for example, with Fennec it works fine.

Silverlight 3 IncreaseQuotaTo fails if I call AvailableFreeSpace first

The following code throws an exception...
private void EnsureDiskSpace()
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForSite())
{
const long NEEDED = 1024 * 1024 * 100;
if (file.AvailableFreeSpace < NEEDED)
{
if (!file.IncreaseQuotaTo(NEEDED))
{
throw new Exception();
}
}
}
}
But this code does not (it displays the silverlight "increase quota" dialog)...
private void EnsureDiskSpace()
{
using (IsolatedStorageFile file = IsolatedStorageFile.GetUserStoreForSite())
{
const long NEEDED = 1024 * 1024 * 100;
if (file.Quota < NEEDED)
{
if (!file.IncreaseQuotaTo(NEEDED))
{
throw new Exception();
}
}
}
}
The only difference in the code is that the first one checks file.AvailableFreeSpace and the second checks file.Quota.
Are you not allowed to check the available space before requesting more? It seems like I've seen a few examples on the web that test the available space first. Is this no longer supported in SL3? My application allows users to download files from a server and store them locally. I'd really like to increase the quota by 10% whenever the user runs out of sapce. Is this possible?
I had the same issue. The solution for me was something written in the help files. The increase of disk quota must be initiated from a user interaction such as a button click event. I was requesting increased disk quota from an asynchronous WCF call. By moving the space increase request to a button click the code worked.
In my case, if the WCF detected there was not enough space, the silverlight app informed the user they needed to increase space by clicking a button. When the button was clicked, and the space was increased, I called the WCF service again knowing I now had more space. Not as good a user experience, but it got me past this issue.
There is a subtle bug in your first example.
There may not be enough free space to add your new storage, triggering the request - but the amount you're asking for may be less than the existing quota. This throws the exception and doesn't show the dialog.
The correct line would be
file.IncreaseQuotaTo(file.Quota + NEEDED);
I believe that there were some changes to the behavior in Silverlight 3, but not having worked directly on these features, I'm not completely sure.
I did take a look at this MSDN page on the feature and the recommended approach is definitely the first example you have; they're suggesting:
Get the user store
Check the AvailableFreeSpace property on the store
If needed, call IncreaseQuotaTo
It isn't ideal, since you can't implement your own growth algorithm (grow by 10%, etc.), but you should be able to at least unblock your scenario using the AvailableFreeSpace property, like you say.
I believe reading the amount of total space available (the Quota) to the user store could be in theory an issue, imagine a "rogue" control or app that simply wants to fill every last byte it can in the isolated storage space, forcing the user eventually to request more space, even when not available.
It turns out that both code blocks work... unless you set a break point. For that matter, both code blocks fail if you do set a break point.

Resources