react-nativereact-native-mapsdirectionreact-native-mapbox-glheremap-navigation

React Native (Track user on following direction (Google Map))


React Native; How we can Monitor The google map Tracking So Actually User drive on line or not, E.g.

if i got the direction from Location A to Location B , So how we can check that User Drive on Line or not.

Basically i can't Monitor it,

E.g

Like as Google Monitor the user Drive on Line , if we D track then ReRoute again.

Actually i want it in react native, So anyOne Help me How we can achieve it or any 3rd party Library, Thanks in Advance.


Solution

  • This Method isPointNearLine is Solve my problem.

    Code Snippet.

    import * as geolib from 'geolib';
    const returnObj=(latitude,longitude)=>{
      return {latitude, longitude}
    }
     const IsLies =  geolib.isPointNearLine(
        returnObj(25.976424, -80.238400), ////point
        returnObj(25.97641, -80.24045), ////start
        returnObj(25.97647,-80.23818), ///end
        20 ////distance in meter
    );
    

    it will return true and false.

    There is another approach is we can user @turf/boolean-point-on-line

    Code Snippet

    var pt = turf.point([74.276089,31.478847]); //// NearPoint
    
    ///Note [[Start Point],[NearPoint],[EndPoint]]
    
    var line = turf.lineString([[74.277908,31.479470],[74.276089,31.478847],[74.274402,31.478452]]);
    var isPointOnLine = turf.booleanPointOnLine(pt, line);
    

    it will also return True and false if Points lies on line.