K
K
krugliybublick2018-03-07 12:26:27
PHP
krugliybublick, 2018-03-07 12:26:27

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

2 answer(s)
M
Maxim Timofeev, 2018-03-07
@webinar

Please give a solution

This is for freelancing
Because it never occurred to anyone that it might be convenient for someone. There are a lot of such solutions (applications) for mobile devices, and thanks to phone sensors, a mobile application can provide accuracy and convenience.
A very dubious idea.
Static distance is a new term in physics. Write a scientific paper urgently.
Data can only be obtained for geo positioning. So you can calculate the distance, but the accuracy will not be high. Plus, the browser will go offline and you can't do anything about it. Why do you need this? Why a person will use your site instead of using a mobile application (there are just thousands of them). In general, there are bracelets for this.
PS: strange idea. Because
- this has already been implemented many times
- this is implemented on the optimal platform, but you chose the strangest one for this, which means that in any case it will turn out 100 times worse than that of competitors.

T
twobomb, 2018-03-07
@twobomb

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.

My Function (C#)
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 question

Ask a Question

731 491 924 answers to any question