Wednesday, September 25, 2013

[android help] How to find whether the device in same location or moving in Android?


How to find whether the device in same location or moving in Android?


gps - How to find whether the device in same location or moving in Android? - Stack Overflow







Tell me more ×

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



double venueLat =latitude
double venueLng = longitude

double latDistance = Math.toRadians(userLat - venueLat);
double lngDistance = Math.toRadians(userLng - venueLng);
double a = (Math.sin(latDistance / 2) * Math.sin(latDistance / 2)) +
(Math.cos(Math.toRadians(userLat))) *
(Math.cos(Math.toRadians(venueLat))) *
(Math.sin(lngDistance / 2)) *
(Math.sin(lngDistance / 2));

double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a));

double dist = 6371 * c;
if (dist<1){ (in km, you can use 0.1 for metres etc.)
/* Include your code here to display your records */
}



















default






Read more

stackoverflow.comm



No comments:

Post a Comment

Google Voice on T-Mobile? [General]

Google Voice on T-Mobile? So I recently switched from a GNex on Verizon to a Moto X DE on T-Mobile. I had always used Google Voice for my v...