+ Reply to Thread
Results 1 to 4 of 4

Google API/distance calculator

  1. #1
    Registered User
    Join Date
    06-06-2017
    Location
    Copenhagen, Danmark
    MS-Off Ver
    2013
    Posts
    3

    Google API/distance calculator

    Hello,

    I am working on this new excel-sheet, that can calculate the kilometers from one place "A" to place "B".

    I have found inspiration online on different forums, and I've ended up using this as the function for VBA. It works like a charm.

    Please Login or Register  to view this content.

    I am using "=G_DISTANCE(C2;C3)" where C2 is "from" and C3 is "to). However, I am looking to add waypoints to the equation, so that I can make sure it follows the actual route I want it to (i.e. using the ferry/or bridge when it's the shortest route).

    I imagined it would look something like "=G_DISTANCE(C2;C3;C4)" where C3 now acts as a waypoint.

    I've been trying and trying, but seeing as I am still somewhat of a novice, I haven't been able to crack it yet.

    Thanks in advance.

  2. #2
    Forum Expert CK76's Avatar
    Join Date
    06-16-2015
    Location
    ONT, Canada
    MS-Off Ver
    MS365 Apps for enterprise
    Posts
    5,973

    Re: Google API/distance calculator

    "=G_DISTANCE(C2;C3;C4)"
    You can't do that without significantly altering the code. As function is set up to accept only 2 arguments (Origin & Destination).

    So if you want to use way point, what you then need is to calculate/run G_Distance twice.
    =G_DISTANCE(Origin, WayPoint)
    =G_DISTANCE(WayPoint, Destination)
    "Progress isn't made by early risers. It's made by lazy men trying to find easier ways to do something."
    ― Robert A. Heinlein

  3. #3
    Forum Guru
    Join Date
    07-25-2011
    Location
    Florida
    MS-Off Ver
    Excel 2003
    Posts
    9,653

    Re: Google API/distance calculator

    This new function calls your original G_DISTANCE function. It loops through each pair of points and sums the distances. You could enter multiple way-points.

    Please Login or Register  to view this content.
    =G_DISTANCE_TOTAL(C2;C3;C4;C5)

    I have not tested this.
    Surround your VBA code with CODE tags e.g.;
    [CODE]your VBA code here[/CODE]
    The # button in the forum editor will apply CODE tags around your selected text.

  4. #4
    Registered User
    Join Date
    06-06-2017
    Location
    Copenhagen, Danmark
    MS-Off Ver
    2013
    Posts
    3

    Re: Google API/distance calculator

    Thanks for the quick answers.

    I tried the G_DISTANCE_TOTAL, but didn't get it up and running.

    Instead I chose to go with the =G_DISTANCE(Origin, WayPoint), and it has pretty much solved the problem for now.

    Again - thanks.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. VBA Route Calculator - Google Maps Api 22 Minutes quicker than Actual Google Website
    By lookingforhelp1 in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 11-06-2015, 01:23 PM
  2. Google Maps - Distance Calculator
    By attaul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2014, 05:24 AM
  3. Excel - Google Maps API Distance Calculator
    By philipryoung in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-11-2014, 06:00 AM
  4. [SOLVED] Google Distance Matrix API - Distance and Time
    By rtcwlomax in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 02-18-2014, 08:42 PM
  5. Google distance and time
    By A[L]C in forum Excel General
    Replies: 5
    Last Post: 12-21-2011, 08:39 AM
  6. Distance Calculator
    By Subwind in forum Excel Programming / VBA / Macros
    Replies: 8
    Last Post: 07-09-2011, 01:04 AM
  7. Use google maps to get distance
    By rdr910 in forum Excel Programming / VBA / Macros
    Replies: 0
    Last Post: 10-13-2010, 09:16 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1