Kilometer

Asked

Viewed 52 times

0

Hello, I need a help, I am creating a game that the more the user walk the more chances to be able to receive rewards but I do not know how to do the kilometer counter and ignore the kms traveled at a speed exceeding 10km/h! Someone can give me a north?

1 answer

0


A simple solution would be to capture the user’s location every minute and check the distance traveled using the Android Location class, 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 value of the distance traveled by a person at 10 km/h in 1 minute), this distance is accounted for.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.