Is it possible to make an HTML5 Trip Meter that tracks distance traveled? - ios

I'm trying to develop a webapp that users can run on their mobile phone to track the distance they've traveled. Think of it as something like RunKeeper, but in webapp form.
The following article describes an easy way to create a Trip Meter with HTML5 and and the Geolocation API.
http://www.html5rocks.com/en/tutorials/geolocation/trip_meter/
However, this just seems to calculate the distance between point A and point B. I suppose I could use something like JavaScript's setTimeout to track the distance traveled every 5 seconds, then calculate the total at the end. However, when the webapp is running in the background (or the phone is locked), this JS won't be executed. Is there any sort of solution to this problem?

You don't need to use setTimeout, the watchPosition will fire the callback function every time the location is updated. However, you are correct that the JavaScript will only run when the web app is not in the background and the phone is not locked. You may be able to write an HTML5 app then convert it to native with something like PhoneGap.

Related

Core Location skips user movements with CLVisit monitoring turned on

The app I'm working on records information about places where user spends most of his/her time. Core Location's Visits monitoring fulfil all it's requirements in location information absolutely.
While testing this app our QA-engineers revealed evidence that Core Location misses Visits for unknown reason. And this is not a result of low location accuracy. Core Location starts skipping locations registered before without any problems.
To make things clear we've run the test. I installed on his phone our app and example app: https://github.com/steveschauer/TestCLVisit
After 3 days of testing we compared locations from our app, sample app and information from Settings->Privacy->Location Services->System Services->Frequent Locations.
Information from all sources was equal. So we can say that it's not an issue of our app.
But while all locations registered at first day was correct, many locations of second and third day were missed. Only few of them were registered.
Is it normal behaviour for Visits Monitoring?
What could be a reason of such skips?
Does anybody have negative or positive experience of Visits monitoring?
Yes, I faced some similar issues while using CLVisit API. There is also an article from NSHipster, which describe some issues with CLVists and these are still present in iOS 10. It essentially goes on to say that if you want infrastructure that extremely precise don't use CLVisit.
From our experience, CLVisit is not all that precise. While start and end times are generally accurate within a minute or two, lines get blurred at the edges of what is and what is not a visit. Ducking into a corner coffee shop for a minute might not trigger a visit, but waiting at a particularly long traffic light might.

What happen when multiple apps use the GPS on iOS?

On iOS we are using the GPS to track users.
We had a strange case last week where a user were moving quite good, and then suddenly one point from the GPS could be totally off (~500 meters), and then moved again and then suddenly a totally off point again (again about 500 meters).
We are using filter and have set the accuracy to only get good GPS-points, and these kind of bad GPS-coordinates is nothing we normally see.
Because of this behaviour I started to think about how the GPS works in iOS when multiple apps are using the GPS at the same time.
We require a good accuracy, We use kCLLocationAccuracyBestForNavigation or kCLLocationAccuracyBest. They should only use the GPS and not any wifi/cellular or similar. We also filter out anything with an accuracy (fault tolerance) higher than 130.
But what happen if another app is also using the GPS with the settings of kCLLocationAccuracyThreeKilometers. Could it be that our app receives those updates and therefore we get bad accuracy because of that?

What is best practice to constantly receive coordinates

I am kind of new to programming and wanted to know what would be the best way to get data from server? To be more specific my app receives GPS coordinates from server (currently using Alamofire) and then shows them on the map.
Now, I don't know how keep those coordinates updated on device. Should I make loop, where app downloads coordinates from server, let's say, every 5 seconds and shows them on the map? Should loop interval be longer? Ideally I would like if an app could show live location - that is get updates from server every second.
Maybe there is library for my specific problem? Where could I read more about this?
And I could upload some of my code, but now it simply get data inviewDidLoad using Alamofire and show it on map.
EDIT: Why do I keep getting down votes? Seriuosly, I would like to know what I did wrong.
Best way is to use socket programming and listen particular socket where coordinates will be pushed from server. Rather than pulling periodically this will be push mechanism where server will push from it's side whenever it has new coordinate available ...
Here is the Apple's guide line for the same
https://developer.apple.com/library/ios/documentation/NetworkingInternet/Conceptual/NetworkingTopics/Articles/UsingSocketsandSocketStreams.html#//apple_ref/doc/uid/CH73-SW4
If this seems like too much you can use pubnub library for ios which is free for 100 devices
Here is the link
https://www.pubnub.com/

What is the time resolution for the callback on YouTube HTML5 API?

We have built an application using the old YouTube flash API which polls the player for it's current time using: player.getCurrentTime(). We currently poll the player at 40ms intervals in order to update screen components at 25 fps. This API isn't supported on iOS so we tested the HTML5 API. It seems that we can not poll the player as frequently as 40ms using the HTML5 API. It appears to max out at about 100ms polling intervals forcing our screen updates to be very jerky. Is this a known limitation of the HTML5 API or is there a way to poll the player at finer intervals?
What function are you using for your polling? If you're using setInterval or setTimeout, you could see if you get less jerky performance with requestAnimationFrame.
Regardless, though, it may not matter; the iframe API (which is the only one that offers HTML5 playback) doesn't have that granular of access to the player's current time. In fact, the player inside the iframe only does a postMessage to update the time accessible via getCurrentTime about 5-6 times a second, so polling any more frequently than that is just wasting CPU cycles. (I'm not sure why they do it this way, as HTML5 video by default updates its current time about 50 times a second).

Firefox OS device gps

I'm currently searching a way for device using firefox OS to communicate with device's gps, so it can get the exact location positioning, rather than the w3c geolocation api which is not as accurate as gps realtime.. Thanks!
Simple answer: it isn't possible to access the "device's GPS" directly. You only have the Geolocation API that you already know.
Long answer: My experience with it is not bad at all. So, I think only of two possibilities for not getting "exact location positioning", as you name it:
maybe you're not using the right options to get a precise position. In this case, you could tweak your options a bit to get better results;
maybe you're not waiting until the underlying software can use your GPS instead of some less accurate instrument/estimation (like Wi-Fi positioning estimation).
It can be a combination of both =P
In the first case, you can verify if you're using enableHighAccuracy, like this:
navigator.geolocation.watchPosition(
successCallback,
errorCallback,
{ enableHighAccuracy: true }
);
This will ask the browser for better results, as the standard indicates. Watch out that this may use more battery, and this may not be available anyway. This may take more time too, which is related to my other observation.
In the second case, you may be using a value for timeout that is too small, and maybe it's combined with a maximumAge that may be too high.
If maximumAge is high and timeout is small, you get an out dated position, as there won't be enough time to get a new position and you accept an old one.
If both are small, you'll start to get lots of TIMEOUT errors (the value is 3), as there'll be no positions for you.
You need to find the right balance between all 3 options to get the best positions. And you have to be patient sometimes.
Play with all 3 options and take a look at the errors you get. They'll tell you a lot about your issue getting precise and accurate coordinates.
The position object has some attributes that may come in handy to analyze what's happaning:
the position.timestamp attribute will tell you how old that position object is. If this is old, you know you should tweak the options
the position.coords.accuracy attribute will tell you the accuracy level of the lat/long coordinates. If this is too big (it's in meters), you know you should tweak the options
If you wait forever, on a place where the GPS should work well (say, outdoors, on a clean field), and you keep getting inaccurate results, maybe you can't do much better anyway. I'd say it's not possible anyway, with your software+hardware =(
As of now, Firefox OS only has support for GPS positioning (with the latest addition of A-GPS in the mix). That results in the fact, that most of the time you will have to wait from 1 to several minutes at least for the GPS module to acquire lock on your location, and you will need clear look at the sky for the lock to be acquired.
That said, after a lock is acquired, by using the right settings in the call itself (like setting the enableHighAccuracy flag to true) the GPS should provide as accurate position as any other device would.
Right now cell-based and wifi-based geolocation is not available in the current version of the OS (1.0.1 or 1.1.0, either) but is in the pipeline.
You can use the Geolocation API Firefox OS or Google Maps (I do not remember where I got it)

Resources