Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6184929
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T01:37:29+00:00 2026-05-24T01:37:29+00:00

The computeDistanceBetween() function in google maps geometry library will not return a value for

  • 0

The computeDistanceBetween() function in google maps geometry library will not return a value for me. Using the alert function it says the distance is “[object, Object]”. Can anyone see where I’m going wrong? here are the important parts of the code in question:

<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false&libraries=geometry"></script>
<script type="text/javascript" >

    var myArray1= [['location1', lat1, lng1], ['location2', lat2, lng2], ...];
    var myArray2= [['locationA', latA, lngA], ['locationB', latB, lngB], ...];
    var arrays = [myArray1, myArray2];

    function codeStart() {
      var orig;
      var startAddress = document.getElementById("start").value;
      geocoder.geocode( { 'address': startAddress}, function(results, status) {
            if (status == google.maps.GeocoderStatus.OK) {
                var i = 0;
                var input = results[0].geometry.location;
                while (i < arrays.length) {             
                    orig = closest(input, arrays[i]);
                }
            }
      });
    }

    function closest(latlng, array){
      var distance;
      var c = 0;
      while (c < array.length){
          var location = array[c];
          var locationlatlng = new google.maps.LatLng(location[1],location[2]);
          distance = new google.maps.geometry.spherical.computeDistanceBetween(latlng, locationlatlng);
          alert(distance);  // popup box says "[object, Object]"
          c++;
      }
    }

</script>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T01:37:29+00:00Added an answer on May 24, 2026 at 1:37 am

    computeDistanceBetween is a static method. So this line:

    distance = new google.maps.geometry.spherical.computeDistanceBetween(latlng, locationlatlng);
    

    should be this instead:

    distance = google.maps.geometry.spherical.computeDistanceBetween(latlng, locationlatlng)
    

    By the way, when alert() tells you that something is an object, it’s a good time to switch to console.dir() instead of alert() so you can (at least in some browsers) look at the contents of the object in the console/dev tools. If you don’t know much about your JavaScript console, check it out. It will save you tons of time.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the google.maps.geometry.spherical's computeDistanceBetween function to get the distance between two points on
I am using Google Maps V3 API to create a polyline with 2 points.
I am newbie in Maps API, i am trying get the distance (in Km)
I have spent hours on a strange problem with the interpolate function of google
I want to calculate the direct distance between to positions in metric form. (ie:
I have markers dotted around a map, and a radius (circle overlay) on a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.