Googlesheet Distance calculation
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;
}
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
Hello did you post it? I emailed you to my friend
Where is it posted please?
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?
honestly, your videos are so easy to follow. Keep up the good job! you are amazing!
Great job! Great tool. Thanks for the knowledge!!!
Love to hear that it was helpful.
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.
It worked! And it wasn't hard! Wow! I think I love you! Thank you!!!
You're welcome!
Make sure to have your script project named "Maps" as well! That solved the problem for me
both the file and project name must be "Maps"
It’s not working can you help
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing
legend@@TalebBekkali
How would I update it so I can measure the miles between postal codes instead of cities?
I dont have a script editor in my tools tab. Is there another way of doing this?
Click the Extensions tab and select Apps Script
@@tiffanyross Did you get it to work?
@@sweetjonesygurl7289 yes
@@sweetjonesygurl7289 you still need help?
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0
I'm having the same issue with miles not calculating. Nothing happens at all. Can you help me, please?
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing
Everything was great I do not have the coding script under my "TOOL" tab. where else can I install the map code?
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.
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
I tried to get this script to work for hours but nothing seems to happen. Great content though!
Me too! i believe the script does not work anymore.
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0
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!
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
Having same issues, Are you still able to help with spreadsheet not calculating?
i cant get the miles to calculate someone please help...great job with the details!!
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing
Did anybody figure out the issue with the miles not calculating?
Mine didnt calculate either
@@myascott9271 Click refresh page
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
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
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
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
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
Does anyone else know where I can place the driving code I do not have edit script under "tools"
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
Taleb, would you please provide that little code as well for distance calculation. Thanks
HELLO, DO YOU KNOW THE CODE FOR RATE?
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
Hi. Did you figure it out?
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
So I see that I am not the only one with calculations not populating.......a lil help, please
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0
could you please send me the spreadsheet?
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
can someone give me the code for the rate please
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit?usp=sharing
Hey, great script. Can u pls help me? I have an issue, miles are not calculating after 1 change. Thank you
Share your sheet with me
Taleb.bekkali@gmail.com
@@TalebBekkali Hey man, I have the same issue, can I share my sheet too?
Any updates on the link for the script code??
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0
I'm having issues with the code, can you help?
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
Please help. It’s not working
docs.google.com/spreadsheets/d/1MMFXJYQVOPljFDjz5K0SzwMcysruvAwDBrUjMVI5-y4/edit#gid=0
I'm having the same issue with miles not calculating. Nothing happens at all. Great spreadsheet by the way!
just follow every single details
@@manjindersingh3259 can you help me
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
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