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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:57:33+00:00 2026-06-13T16:57:33+00:00

Why my code not display distance and duration? This is my code(html + js):

  • 0

Why my code not display distance and duration?

This is my code(html + js):

<!DOCTYPE html>
<html>
   <head>
      <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
      <meta charset="utf-8" />
      <title>Google</title>
      <script src="https://maps.googleapis.com/maps/api/js?sensor=false"></script>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
      <style type="text/css">
         #result{
         width: 300px;
         height: 400px;
         background-color: red;
         }
      </style>

      <script>
         var service = new google.maps.DistanceMatrixService();
         service.getDistanceMatrix(
         {
         origins: ["Berlin"],
         destinations: ["Frankfurt"],
         travelMode: google.maps.TravelMode.DRIVING,
         }, callback);

         function callback(response, status) {
         $("#result").text(response.rows[0].elements.distance.text + " and " + response.rows[0].elements.duration.text);
         }
      </script>
   </head>

   <body>
      <div id="result"></div>
   </body>
</html>

This is example JSON output:

http://maps.googleapis.com/maps/api/distancematrix/json?origins=Berlin&destinations=Frankfurt&mode=driving&language=de-DE&sensor=false

  • 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-13T16:57:35+00:00Added an answer on June 13, 2026 at 4:57 pm

    elements is also an array, so your callback function has to look like this:

     function callback(response, status) {
         $("#result").text(response.rows[0].elements[0].distance.text + " and " + response.rows[0].elements[0].duration.text);
     }
    

    Here is a working JSfiddle.

    Hint: use the Javascript console to see errors in your Javascript.

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

Sidebar

Related Questions

I want to display data from database in DataGridView...This is my code...Its not working...Can
I am confused about why this code does not display any image: In the
I would like to use a spinner. But, this code below does not display
A DataGridView bound by this code does not display information as expected: dataGridView1.DataSource =
My code seems to run but it does not display the result any result
I have no code to really display here, since I have not been able
I want display data from database in Listbox...Here is my code, It is not
Why does this code not print an exception stack trace? public class Playground {
How does the SpotLocation work? The following code will not display digital signature request(DSR)
WebView Does not display. my code is WebViewController.m #import WebViewController.h @interface WebViewController () @end

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.