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 8082191
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:00:17+00:00 2026-06-05T17:00:17+00:00

I am having a problem with the service.getDistanceMatrix call. <html> <head> <script type=text/javascript src=http://maps.google.com/maps/api/js?sensor=false>

  • 0

I am having a problem with the service.getDistanceMatrix call.

<html>
<head>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?sensor=false">    </script>
<script type="text/javascript">

origin = "Chicago, IL";
destination = "Springfield, IL";
service = new google.maps.DistanceMatrixService();

service.getDistanceMatrix(
{
    origins: [origin],
    destinations: [destination],
    travelMode: google.maps.TravelMode.DRIVING,
    unitSystem: google.maps.UnitSystem.IMPERIAL,
    avoidHighways: false,
    avoidTolls: false
}, 
callback
);

function callback(response, status) {
var orig = document.getElementById("orig"),
    dest = document.getElementById("dest"),
    dist = document.getElementById("dist");

if(status=="OK") {
    orig.value = response.originAddresses[0];
    dest.value = response.destinationAddresses[0];
    dist.value = response.rows[0].elements[0].distance.text;
} else {
    alert("Error: " + status);
}
}

function doIt() {
origin1 = document.getElementById("orig");
destination1 = document.getElementById("dest");
service1 = new google.maps.DistanceMatrixService();


service1.getDistanceMatrix(
   {
        origins: [origin1],
        destinations: [destination1],
        travelMode: google.maps.TravelMode.DRIVING,
        unitSystem: google.maps.UnitSystem.IMPERIAL,
        avoidHighways: false,
        avoidTolls: false
    }, 
callback1
);


}

function callback1(response, status) {

if(status=="OK") {
    orig.value = response.originAddresses[0];
    dest.value = response.destinationAddresses[0];
    dist.value = response.rows[0].elements[0].distance.text;
} else {
    alert("Error: " + status);
}
}



</script>
</head>
<body>
<br>
Basic example for using the Distance Matrix.<br><br>
Origin: <input id="orig" type="text" style="width:35em"><br><br>
Destination: <input id="dest" type="text" style="width:35em"><br><br>
Distance: <input id="dist" type="text" style="width:35em">
<button onClick="doIt()">Distance</button>
</body>
</html>

Most of this was taken directly from a google sample.
However, I am trying to add a button to refresh the form.
Something seems to be wrong in service1.getDistanceMatrix.
It seems to say error 0.

Any ideas to fix this?

thank you

  • 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-06-05T17:00:18+00:00Added an answer on June 5, 2026 at 5:00 pm

    These references need .value at the end:

    service1.getDistanceMatrix(
       {
        origins: [origin1.value],
        destinations: [destination1.value],
    

    Personally I would use document.getElementById for orig, dest and dist below (I feel it’s safer because it is more precise), but the way it is written it also works. I am a bit puzzled because I didn’t think it would work. There is orig, dest, dist defined in the first callback above but I don’t think they would be visible in callback1.

    function callback1(response, status) {
    
    if(status=="OK") {
        orig.value = response.originAddresses[0];
        dest.value = response.destinationAddresses[0];
        dist.value = response.rows[0].elements[0].distance.text;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Having a problem executing a Python script from a .NET web service. The web
Having problem to open form in new window, script is pulled from external service.
I'm having the problem described here: http://groups.google.com/group/microsoft.public.xml.soap/browse_thread/thread/029ee5b5d4fa2440/0895d73c5c3720a1 I am consuming a Web Service using
I'm having some problem consuming REST Service and want to figure out what I'm
I'm having a problem with a WCF service trying to consume it from Java.
I am having a problem creating a WCF service instance with a parameter. The
I am having a minor problem with WCF service proxies where the message contains
The problem i'm having is that i've created a web service, and a windows
I'm having a problem compiling my Java program: \Desktop\Java Programming\JFrameWithPanel.java:79: unexpected type required: variable
I'm having a problem with binding service to an activity. I get playing_service==null. I

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.