I'm using CMMotionActivity
and trying to distinguish between car, train and bus when the framework return automotive
type.
This is not possible only using CoreMotion
, so I think it's necessary to use a 3rd party service, such as cloud service or 3rd party framework.
Has anyone got to face the same problem? Thanks
I had the same problem a while back. Long story short, it's pretty much impossible from anything in existence. However, it is not too hard to bake it yourself. Here's how I solved it-
My app had background location permission, in addition to motion permission. The background location kept the app alive. As you might know, you can't enable the location monitoring from background, but you can keep it alive for as long as you want, and you can change the quality of service from the background. To avoid draining battery, I set it to the lowest quality of data possible, so that it basically had no effect on power consumption when idle. That way, you have background access to motion data with an ability to enable precise location tracking without opening the app, you just have to never shut off location monitoring.
I used this background permission to monitor the motion data, and whenever it changed to automotive
with a certain confidence threshold, I upped the location data quality to the best available, and stored it to disk as soon as possible. When the motion chip reported walking
or some other non-automotive activity, indicating that the automotive session had ended, I prompted the user to open the app to fill in other details (this was a driving tracker for tax purposes). When the user opened the app, I pulled train track data from a map provider, and ran a quick "algorithm" to detect if the automotive activity was correlated with any train tracks. If it was with a certain confidence, I discarded the data as I did not need it, but that's what you should do. Just correlate high-quality location data with map data of train tracks.
I got my train track data from my countries government as it's open, but I suppose other map providers have this data available as well.
Hopefully this helps you out, sorry I could not provide a prebaked service!