How to find whether the device in same location or moving in Android?
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.
In Android, I am getting locations for every 30 seconds by GPS using alarm manager. I want to detect whether the device is traveling or presence at same location using geopoints. If the device in same location GPS getting some times accurate data some times getting approximate data at the time 20 or 30 meter away from accurate location displaying on map. So it's getting problem on finding device traveling. How to find device is not traveling? | ||||
Every 30 seconds when you get the new locations you can compare it with the previous location to see if there is any difference in location and determine if the device is travelling. | |||
You can write code in onLocationChanged() method. There you will get new latitude longitude each and everytime when device changed its position. OnLocationChange() method called only if location has been changed. But if you want some specific distance wise calculations then you have to calculate distance between older lat-long and newer one. You can find distance using lat-long. | |||
As the GPS signal recieved can vary even it's in the same position, you can't just compare the new location with the old one. I would use something like the following code
| |||
default
Read more
stackoverflow.comm
No comments:
Post a Comment