Your IP : 216.73.216.91


Current Path : /var/node/inatote/Inatote-Backend/helpers/
Upload File :
Current File : /var/node/inatote/Inatote-Backend/helpers/calculateDistance.js

import config  from "../config.js";
import axios from "axios";
let serverKey = config.app.googleMapApiKey;

let calculateDistanceFromLatLong =async (origin  , destination)=>{
    
        var config = {
            method: 'get',
            url: `https://maps.googleapis.com/maps/api/directions/json?origin=${origin.lat},${origin.long}&destination=${destination.lat},${destination.long}&key=${serverKey}&mode=DRIVING`,
            headers: { }
          };
          console.log("CONFIG" , config.url);
          
          let response = await axios(config);
          if(response.status == 200){
            if(response.data.routes.length == 0){
                return null
            }else{
                var routes = response.data.routes.length > 0 ? response.data.routes[0] : [];
            console.log("routes" , routes.legs[0] );
            return routes && routes.legs && routes.legs.length > 0 ?  routes.legs[0] : []
        
            }
        
        }
          
    
      
}

export default calculateDistanceFromLatLong;