Googlesheet Distance calculation

Sdílet
Vložit
  • čas přidán 5. 09. 2024
  • function DrivingMeters(origin, destination) {
    var directions = Maps.newDirectionFinder()
    // .setMode(Maps.DirectionFinder.Mode.TRANSIT)
    .setOrigin(origin)
    .setDestination(destination)
    .getDirections();
    if (directions && directions.error_message) throw directions.error_message
    if (directions && directions.routes && directions.routes[0] && directions.routes[0].legs && directions.routes[0].legs[0] && directions.routes[0].legs[0].distance)
    return directions.routes[0].legs[0].distance.value;
    return "";
    }
    function DrivingMiles(origin, destination) {
    return DrivingMeters(origin, destination)/1609.34;
    }
    function DrivingSeconds(origin, destination) {
    var directions = Maps.newDirectionFinder()
    // .setMode(Maps.DirectionFinder.Mode.TRANSIT)
    .setOrigin(origin)
    .setDestination(destination)
    .getDirections();
    if (directions && directions.error_message) throw directions.error_message
    if (directions && directions.routes && directions.routes[0] && directions.routes[0].legs && directions.routes[0].legs[0] && directions.routes[0].legs[0].duration)
    return directions.routes[0].legs[0].duration.value;
    return "";
    }
    function DrivingHours(origin, destination) {
    return DrivingSeconds(origin, destination)/(60*60);
    }
    function FlyingMeters(origin,destination) {
    var geoOrigin = Maps.newGeocoder().geocode(origin);
    var geoDestination = Maps.newGeocoder().geocode(destination);
    return haversine({lat:geoOrigin.results[0].geometry.location.lat,lng:geoOrigin.results[0].geometry.location.lng},
    {lat:geoDestination.results[0].geometry.location.lat,lng:geoDestination.results[0].geometry.location.lng});
    }
    function FlyingMiles(origin,destination) {
    return crowFliesMeters(origin,destination)/1609.34;
    }
    function haversine(latLng1, latLng2) {
    var radius = 6371000;
    var dLat = (latLng2.lat-latLng1.lat) * Math.PI/180;
    var dLng = (latLng2.lng-latLng1.lng) * Math.PI/180;
    var a = Math.sin(dLat/2) * Math.sin(dLat/2) +
    Math.cos(latLng1.lat * Math.PI/180) * Math.cos(latLng2.lat * Math.PI/180) *
    Math.sin(dLng/2) * Math.sin(dLng/2);
    var c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1-a));
    var d = radius * c;
    return d;
    }

Komentáře • 73

  • @TalebBekkali
    @TalebBekkali  Před 2 lety +7

    Sorry guys, When I posted the code google deleted some characters, I have to post the code somewhere else online, I will share the link shortly

    • @chocolatesunflower2386
      @chocolatesunflower2386 Před 2 lety

      Hello did you post it? I emailed you to my friend

    • @sweetjonesygurl7289
      @sweetjonesygurl7289 Před 2 lety

      Where is it posted please?

    • @Idealvisionrealty
      @Idealvisionrealty Před rokem

      Everything was great I do not have the coding script under my "TOOL" tab. where else can I install the map code? and where did you repost it, and is this now the right code?

  • @jamafricanprincess
    @jamafricanprincess Před 2 lety +1

    honestly, your videos are so easy to follow. Keep up the good job! you are amazing!

  • @shannonmcdowell4386
    @shannonmcdowell4386 Před rokem +1

    Great job! Great tool. Thanks for the knowledge!!!

  • @vnice34
    @vnice34 Před 3 lety

    I was finally able to get this to work. It was my error at some point in one of videos he hide line 9 of spreadsheet. I did not and I was entering the codes in the wrong line. Not sure if this is the same issue others are having but once I hide line 9 and enter the the codes it worked like a charm.

  • @randomhuman5636
    @randomhuman5636 Před 11 měsíci

    It worked! And it wasn't hard! Wow! I think I love you! Thank you!!!

  • @luccabarossi2729
    @luccabarossi2729 Před 2 lety

    Make sure to have your script project named "Maps" as well! That solved the problem for me

  • @user-xn9jx7si1g
    @user-xn9jx7si1g Před 5 měsíci

    How would I update it so I can measure the miles between postal codes instead of cities?

  • @danisaac9469
    @danisaac9469 Před 2 lety +2

    I dont have a script editor in my tools tab. Is there another way of doing this?

    • @tiffanyross
      @tiffanyross Před 2 lety +1

      Click the Extensions tab and select Apps Script

    • @sweetjonesygurl7289
      @sweetjonesygurl7289 Před 2 lety

      @@tiffanyross Did you get it to work?

    • @tiffanyross
      @tiffanyross Před 2 lety

      @@sweetjonesygurl7289 yes

    • @tiffanyross
      @tiffanyross Před 2 lety

      @@sweetjonesygurl7289 you still need help?

    • @TalebBekkali
      @TalebBekkali  Před 2 lety +1

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0

  • @ashleysimmons7000
    @ashleysimmons7000 Před 2 lety +2

    I'm having the same issue with miles not calculating. Nothing happens at all. Can you help me, please?

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @Idealvisionrealty
    @Idealvisionrealty Před rokem

    Everything was great I do not have the coding script under my "TOOL" tab. where else can I install the map code?

  • @ziplifetransportinc3796

    Thank you very much. This was very helpful, and informative. Are you still active? I wanted to subscribe but it looks like you haven't posted any content, in a while. Nonetheless, thank you.

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @vnice34
    @vnice34 Před 3 lety +2

    I tried to get this script to work for hours but nothing seems to happen. Great content though!

    • @MsBee-ct4nw
      @MsBee-ct4nw Před 2 lety

      Me too! i believe the script does not work anymore.

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0

  • @willbrownjr6753
    @willbrownjr6753 Před 3 lety +1

    Hello! Awesome Spreadsheet. I also am Having trouble getting the sheet to calculate mileage. I'd Be glad to send you my sheet or if you could help that would be greatly appreciated. Thank you!

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @michaelhall6831
    @michaelhall6831 Před 3 lety

    Having same issues, Are you still able to help with spreadsheet not calculating?

  • @logisticspirates5987
    @logisticspirates5987 Před 2 lety

    i cant get the miles to calculate someone please help...great job with the details!!

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @garyp6492
    @garyp6492 Před 3 lety +1

    Did anybody figure out the issue with the miles not calculating?

    • @myascott9271
      @myascott9271 Před 3 lety

      Mine didnt calculate either

    • @tiffanyross
      @tiffanyross Před 2 lety

      @@myascott9271 Click refresh page

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @ervisdeliu8603
    @ervisdeliu8603 Před 3 lety

    Can someone help out? When i click "Script Editor" i get an error message saying "Sorry, unable to open the file at this time. Please check the address and try again" i have tried several times but nothing

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @Idealvisionrealty
    @Idealvisionrealty Před rokem

    Does anyone else know where I can place the driving code I do not have edit script under "tools"

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @aden1141
    @aden1141 Před 3 lety

    Taleb, would you please provide that little code as well for distance calculation. Thanks

  • @osmandispatcher5531
    @osmandispatcher5531 Před 3 lety

    Hello, please email me the spreadsheet as well, because i'm having the same problem as well with calculating miles. Thanks a lot! I'm very excited to start using it

    • @ksmith081991
      @ksmith081991 Před 2 lety

      Hi. Did you figure it out?

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @_JandA_
    @_JandA_ Před 2 lety

    So I see that I am not the only one with calculations not populating.......a lil help, please

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0

  • @JoltMarketingManager
    @JoltMarketingManager Před rokem

    could you please send me the spreadsheet?

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @gtsdispatch6994
    @gtsdispatch6994 Před 2 lety

    can someone give me the code for the rate please

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @stevenazar4805
    @stevenazar4805 Před 3 lety

    Hey, great script. Can u pls help me? I have an issue, miles are not calculating after 1 change. Thank you

    • @TalebBekkali
      @TalebBekkali  Před 3 lety

      Share your sheet with me
      Taleb.bekkali@gmail.com

    • @kevinthafrenchmf2074
      @kevinthafrenchmf2074 Před 3 lety

      @@TalebBekkali Hey man, I have the same issue, can I share my sheet too?

  • @theresias89
    @theresias89 Před 2 lety

    Any updates on the link for the script code??

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0

  • @lissettealmonte5066
    @lissettealmonte5066 Před 3 lety

    I'm having issues with the code, can you help?

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

  • @sweetjonesygurl7289
    @sweetjonesygurl7289 Před 2 lety

    Please help. It’s not working

    • @TalebBekkali
      @TalebBekkali  Před 2 lety

      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0

  • @prestonhukill8503
    @prestonhukill8503 Před 3 lety

    I'm having the same issue with miles not calculating. Nothing happens at all. Great spreadsheet by the way!

    • @manjindersingh3259
      @manjindersingh3259 Před 3 lety

      just follow every single details

    • @MyTJAMAL
      @MyTJAMAL Před 3 lety

      @@manjindersingh3259 can you help me

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing

    • @TalebBekkali
      @TalebBekkali  Před 10 měsíci

      Hi there, I am sending you a working sample sheet, Please click file ==> download so you can have your own copy.
      docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing