+ Reply to Thread
Results 1 to 9 of 9

Google drive distance function between latitude, longitude.

  1. #1
    Registered User
    Join Date
    05-16-2020
    Location
    poteau, oklahoma
    MS-Off Ver
    360
    Posts
    21

    Google drive distance function between latitude, longitude.

    I need a google function code, vba, that will get the driving distance in miles , between lat and long locations. I have a function for Bing Maps, but it doesn't provide the accuracy that google mapping does. I have my own Google " api key". I've tried several vba's that I found online they just don't seem to be working or include drive times and other information I don't need.

    FYI I have a spreadsheet that has multiple lat and longs that I have to find the mileage for multiple destinations. It is very time consuming on google web map putting them in.

    Any help appreciated, its my day job.

  2. #2
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Google drive distance function between latitude, longitude.

    How far apart are the longitude points and how accurate do the results have to be.
    For smaller distances it may be easier to assume a Euclidean plane and use Pythogoras theorem where differences in Latitude are ~ 69 ,miles per degree and at your latitude location a degree of longitude ~56 miles
    Richard Buttrey

    RIP - d. 06/10/2022

    If any of the responses have helped then please consider rating them by clicking the small star icon below the post.

  3. #3
    Registered User
    Join Date
    05-16-2020
    Location
    poteau, oklahoma
    MS-Off Ver
    360
    Posts
    21

    Re: Google drive distance function between latitude, longitude.

    Quote Originally Posted by Richard Buttrey View Post
    How far apart are the longitude points and how accurate do the results have to be.
    For smaller distances it may be easier to assume a Euclidean plane and use Pythogoras theorem where differences in Latitude are ~ 69 ,miles per degree and at your latitude location a degree of longitude ~56 miles
    They are typically within 5 to 10 miles of each other in the same county. When I attempt with bing it takes the long way around or doesn't have all the roads listed. I'm good with typical drive times from point a to point b. My points are always long and lats because the areas I use are not physical addresses.

  4. #4
    Forum Moderator - RIP Richard Buttrey's Avatar
    Join Date
    01-14-2008
    Location
    Stockton Heath, Cheshire, UK
    MS-Off Ver
    Office 365, Excel for Windows 2010 & Excel for Mac
    Posts
    29,464

    Re: Google drive distance function between latitude, longitude.

    OK,

    But note these are not ROAD distances but straight line
    The simple Pythagoras version - numbers are Degrees
    With Lat 1 in A1, Lat 2 in A2, Long 1 in B1 & Long B in B2
    Distance in miles is given by

    Formula: copy to clipboard
    Please Login or Register  to view this content.


    For a more accurate calculation over longer distances where there are large changes of latitude then the Haversine formula is better
    In C1 enter =RADIANS(A1), C2 =RADIANS(A2), D1 =RADIANS(B1), D2 =RADIANS(B2)
    Apply the following range names C1: LATA, C2: LATB, D1: LONA, D2: LONB

    Then the distance formula is
    Formula: copy to clipboard
    Please Login or Register  to view this content.

  5. #5
    Registered User
    Join Date
    05-16-2020
    Location
    poteau, oklahoma
    MS-Off Ver
    360
    Posts
    21

    Re: Google drive distance function between latitude, longitude.

    Okay thank you , I do have to have driving distances since the transport mode is vehicles. I need a formula that uses the google api. I have found google drive distances to be the most accurate for my work.

  6. #6
    Forum Guru
    Join Date
    08-05-2004
    Location
    NJ
    MS-Off Ver
    365
    Posts
    13,582

    Re: Google drive distance function between latitude, longitude.

    Does this link help?
    https://analystcave.com/excel-calcul...een-addresses/
    includes directions for coordinates
    ChemistB
    My 2?

    substitute commas with semi-colons if your region settings requires
    Don't forget to mark threads as "Solved" (Edit First post>Advanced>Change Prefix)
    If I helped, Don't forget to add to my reputation (click on the little star at bottom of this post)

    Forum Rules: How to use code tags, mark a thread solved, and keep yourself out of trouble

  7. #7
    Registered User
    Join Date
    05-16-2020
    Location
    poteau, oklahoma
    MS-Off Ver
    360
    Posts
    21

    Re: Google drive distance function between latitude, longitude.

    I have tried this one before, it keeps coming back with the -1 error in the calculation box.

  8. #8
    Valued Forum Contributor Haluk's Avatar
    Join Date
    02-14-2019
    Location
    Turkiye
    MS-Off Ver
    2010 - 64 Bit on Windows-11 (22 H2) 64 Bit
    Posts
    1,150

    Re: Google drive distance function between latitude, longitude.

    @okamymiller; Did you try it with your own API key?

  9. #9
    Registered User
    Join Date
    05-16-2020
    Location
    poteau, oklahoma
    MS-Off Ver
    360
    Posts
    21

    Re: Google drive distance function between latitude, longitude.

    Yes I put in my own API I created at google. I've seen this same error from others trying to use this code as well. I don't know enough about VBA to figure out whats wrong with it.

+ 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. Need help with my distance formula using latitude & longitude.
    By odimas in forum Excel Formulas & Functions
    Replies: 0
    Last Post: 01-24-2014, 11:53 PM
  2. Convert distance to Latitude and longitude
    By mrkhalidiwfm in forum Excel Formulas & Functions
    Replies: 3
    Last Post: 04-08-2013, 02:34 AM
  3. Distance between latitude and longitude
    By fazna ali in forum Excel General
    Replies: 2
    Last Post: 11-06-2012, 05:03 AM
  4. Distance Formula for Latitude and Longitude
    By dankappa in forum Excel General
    Replies: 4
    Last Post: 11-06-2012, 01:50 AM
  5. Determining distance using Latitude & Longitude
    By KeithRoberts in forum Excel General
    Replies: 2
    Last Post: 03-21-2012, 02:59 PM
  6. Latitude and Longitude: Minimize distance
    By gcool12 in forum Excel Programming / VBA / Macros
    Replies: 1
    Last Post: 01-13-2010, 06:18 PM
  7. Determining Distance from Latitude and Longitude
    By morchard in forum Excel General
    Replies: 3
    Last Post: 01-24-2006, 08:45 PM
  8. Can distance be calculated using latitude and longitude?
    By Paxton in forum Excel Formulas & Functions
    Replies: 1
    Last Post: 05-02-2005, 10:06 AM

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