Kilometer Counter

0
Hello, I need a help, I am creating a game that the more the user walk the more chances of being able to receive rewards but I do not know how to do the kilometer counter and ignores the kilometers traveled at a higher speed at 10km / h! Can someone give me a north?

    
asked by anonymous 09.09.2018 / 20:35

1 answer

0

A simple solution would be to capture the user's location every minute and check the distance traveled using the Location class of Android, as shown in the code below.

Location localizacaoA = new Location("Ponto A");

localizacaoA.setLatitude(latA);
localizacaoA.setLongitude(lngA);

Location localizacaoB = new Location("Ponto B");

localizacaoB.setLatitude(latB);
localizacaoB.setLongitude(lngB);

float distancia = localizacaoA.distanceTo(localizacaoB); // Em metros

If the distance in this period was less than 180 meters (approximate distance traveled by a person at 10 km / h in 1 minute), this distance is counted.

    
10.09.2018 / 02:56