Answer the question
In order to leave comments, you need to log in
Is it possible to read the distance traveled from the site?
Hello everyone. Now there will be a very stupid question. I am doing web development, which I will transfer to the application. The task is this. There are registered users. It is necessary that the start button triggers a sensor that will measure the distance traveled (static), that is, it is initially set how much it needs to go. Is it possible to do this on the site? Logging in from the phone? So that after walking 200 meters he counted the time and tracked of course that he walked 200 meters? Please give me a solution. I can’t find anything. Preferably whichever is sooner. I want to pay on the site first.
Answer the question
In order to leave comments, you need to log in
Please give a solution
The first thing that came to my mind was to use some kind of api to work with geolocation like this . Then get the current coordinates Geolocation.getCurrentPosition()
. Request them for example every second, then I don’t remember, but you need to look for a formula for determining the distance between two points. Well, in the end, traveled_distance += distance_between_two_points (previous_coordinates, current_coordinates);
Krch I did not work with this, but if you think about it, you can come up with something.
PS Once there was a need to determine the distance between two points, I wrote a function in C #, I think it would not be difficult to rewrite it in javascript. But there, the distance was usually hundreds of kilometers, so super accuracy was not important.
static public double GPSTracker(Point pnt1, Point pnt2)
{
//pnt1, pnt2 - точки между которыми вычисляются расстояния
// rad - радиус сферы (Земли), num - количество знаков после запятой
//Отладка по входным данным (77.1539, 120.398) (77.1804,129.55) return dist 225883 angle 84.7925159033
//x - широта,y - долгота
int rad = 6372795;
double lat1, lat2, long1, long2;
//получение координат точек в радианах
lat1 = pnt1.X * Math.PI / 180;
long1 = pnt1.Y * Math.PI / 180;
lat2 = pnt2.X * Math.PI / 180;
long2 = pnt2.Y * Math.PI / 180;
//косинусы и синусы широт и разниц долгот
double cl1 = Math.Cos(lat1);
double cl2 = Math.Cos(lat2);
double sl1 = Math.Sin(lat1);
double sl2 = Math.Sin(lat2);
double delta = long2 - long1;
double cdelta = Math.Cos(delta);
double sdelta = Math.Sin(delta);
//вычисления длины большого круга
double y = Math.Sqrt(Math.Pow(cl2 * sdelta, 2) + Math.Pow(cl1 * sl2 - sl1 * cl2 * cdelta, 2));
double x = sl1 * sl2 + cl1 * cl2 * cdelta;
double ad = Math.Atan2(y, x);
double dist = ad * rad;
//вычисление начального азимута
x = (cl1 * sl2) - (sl1 * cl2 * cdelta);
y = sdelta * cl2;
double z = (Math.Atan(-y / x)) * 180 / Math.PI;
if (x < 0)
z = z + 180;
double z2 = (z + 180) % 360 - 180;
z2 = -z2 * Math.PI / 180;
double anglerad2 = z2 - ((2 * Math.PI) * Math.Floor((z2 / (2 * Math.PI))));
double angledeg = (anglerad2 * 180) / Math.PI;
//возврат значений длины большого круга и начального азимута
//return dist, angledeg
return dist;//метров
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question