+ Reply to Thread
Results 1 to 4 of 4

Find the distance between locations using Google Maps?

  1. #1
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Find the distance between locations using Google Maps?

    Hi guys!

    I am trying to adapt something I've found on another site but it's just over my head. I just want to be able to have LOCATION A in A1 and LOCATION B in B1, and in C1 calculate the driving distance between them both in kilometres.

    Here is the code that should return the distance and does work in their sample book, I just don't understand it.

    Please Login or Register  to view this content.
    Please can somebody help me?

    Thank you!

  2. #2
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: Find the distance between locations using Google Maps?

    Well, this code (function) is based on a data structure created within a workbook.
    The data is stored in a named range called urlForDistance
    The function returns 2 element array (vector) containing distance and time.
    This result in a full code (you have shown just one, most important function) is used in some other function or procedure to show the result.

    But you wrote just "another site" :-( not giving it's name or link to it. So I'll not analyze it further, but with 3 small changes I'll make an UDF returning a number out of it (you could say it's 4 changes, but change 1a could be ommitted - it just ensures recalculation).

    UDF can be used as any built in function, so if you have say Brisbane in A1 and Adelaide in B1 in C1 you could write:
    Formula: copy to clipboard
    Please Login or Register  to view this content.


    The code is:
    Please Login or Register  to view this content.
    PS. As you can see in change2 I made it "Australia specific" and limited just to city centers.
    Attached Files Attached Files
    Last edited by Kaper; 08-08-2018 at 05:09 AM.
    Best Regards,

    Kaper

  3. #3
    Registered User
    Join Date
    10-26-2013
    Location
    Melbourne, Australia
    MS-Off Ver
    Excel 2016
    Posts
    56

    Re: Find the distance between locations using Google Maps?

    Thank you so much for your effort Kaper.

    I didn't link to the site as I thought it might be against the forum rules, here is the page http://learnexcelmacro.com/wp/2016/1...-in-excel-vba/

    A lot of what you have written has gone over my head but I'm trying to follow along. Your attached file just returns a #VALUE! error on my computer though and I'm not sure why. I copy your code above and I can see that it tries to calculate something but it just gives me an error, any idea why?

  4. #4
    Forum Guru Kaper's Avatar
    Join Date
    12-14-2013
    Location
    Warsaw, Poland
    MS-Off Ver
    most often: Office 365 in Windows environment
    Posts
    8,626

    Re: Find the distance between locations using Google Maps?

    Hi,
    Have you tried to download and analyze VBA code in a file available at that page (download button near the bottom of the main content)?
    It works exactly as I described.

    The error you are getting is probably because of exceeded limit of free API calls (you may use shared IP assigned by your ISP, etc. so not necessary it was you in person who used the free API).

    You may try to show this changing function definition to:
    Please Login or Register  to view this content.
    and then add check for the exceeded free API access flag in the code:

    Please Login or Register  to view this content.
    If the situation repeats (may be try using other internet connection - may be via mobile network etc.) , you may consider using API key (but I suspect it's no longer free - you probably have to pay some subscription fee to google).

+ 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. Excel - Google maps. Distance between two postcodes
    By pauldaddyadams in forum Excel General
    Replies: 2
    Last Post: 12-04-2015, 01:32 PM
  2. Distance equations w/ google maps?
    By jhow77 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 09-20-2014, 09:44 PM
  3. Google Maps - Distance Calculator
    By attaul in forum Excel Programming / VBA / Macros
    Replies: 2
    Last Post: 08-12-2014, 05:24 AM
  4. Excel - Google Maps API Distance Calculator
    By philipryoung in forum Excel Programming / VBA / Macros
    Replies: 15
    Last Post: 03-11-2014, 06:00 AM
  5. Calculate Distance using Google Maps
    By excelinexcel7 in forum Excel General
    Replies: 2
    Last Post: 12-06-2012, 06:19 PM
  6. Use mapquest or google maps to get driving distance?
    By DonkeyOte in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 10-19-2010, 10:04 PM
  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