Detect if device has taken a turn using location service android -


i want detect if user has taken turn on road while driving using sensors on android phone. how code this? collecting data live sensors(accelerometer,location,rotation,geomagnetic) , storing them on sd card. want know whether user has taken turn , in direction has turned.

i assume registration of sensor done properly. can detect direction using orientation sensor (deprecated) follows:

@override public void onsensorchanged(sensorevent event) {      float azimuth_angle = event.values[0];     int precision = 2;      if (prevazimuth - azimuth_angle < precision * -1)         log.v("->", "right");      else if (prevazimuth - azimuth_angle > precision)         log.v("<-", "left");      prevazimuth = azimuth_angle;  } 

note: variable of "prevazimuth" declared global. can change "precision" value whatever want. need value because not want see output after each trivial change in azimuth angle. however, large precision gives imprecise results. me, "2" optimum.


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -