469,076 Members | 2,013 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,076 developers. It's quick & easy.

Cannot read property "text"of undefined

5
i have the following function for calculating distances.this function is the distance call back function.it goes throught all the alert statements but when it reaches the line in bold it throws an errorcannot read proprty "text of undefined".Is there anything i did wrong above such that my code cannot pass through this statement


Expand|Select|Wrap|Line Numbers
  1. function calculateDistanceCallback(response, status) {
  2.  
  3.                  if (status != google.maps.DistanceMatrixStatus.OK) {
  4.                    alert('Error was: ' + status);
  5.                  } else {
  6.                      alert("in else");
  7.                    var origins = response.originAddresses;
  8.                    var destinations = response.destinationAddresses; 
  9.                    var outputDiv = document.getElementById('outputDiv');
  10.  
  11.                    outputDiv.innerHTML = '';
  12.                    //deleteOverlays();
  13.                    for (var i = 0; i < origins.length; i++) {
  14.                        alert("in forloop");
  15.                      var results = response.rows[i].elements;
  16.                      alert("results" +results);
  17.                      alert("in second for loop");
  18.                      for (var j = 0; j < results.length; j++) {
  19.                          alert("insyd second for loop");
  20.  
  21.                          alert("results" +results[j]);
  22.                      var a = results[j].distance.text.split(" ")[0];
  23.  
  24.                    alert("inbtwn for loop");
  25.                      workingDistance = a;
  26.  
  27. ///more code here
Feb 27 '14 #1
7 3272
Dormilich
8,651 Expert Mod 8TB
that’s because results[j] is not an object (or does not contain a distance property, but the alert() above pretty much rules that out).
Feb 27 '14 #2
belz
5
My code goes up to the alert which says second for loop.so what should i do to make the code work.can you write the code for me containing the change
Feb 27 '14 #3
Dormilich
8,651 Expert Mod 8TB
there’s another alert() beneath that one, what does it show?
Feb 27 '14 #4
belz
5
hi.am using alerts as debug statements.lyk i said my code goz up to the alert wch says results +resulte[j].it doesnt proceed to go and print out the other alerts.meaning the prroblem is were ere is e distance.text code.bcz dats e only code inbtwn e 2 alert statrnents
Mar 3 '14 #5
Dormilich
8,651 Expert Mod 8TB
lyk i said my code goz up to the alert wch says results +resulte[j]
and if that alert doesn’t show "[object Object]", then post #2 applies—you’re working with the wrong array.
Mar 3 '14 #6
belz
5
it does produce object Object.then doesnt proceed
Mar 3 '14 #7
Dormilich
8,651 Expert Mod 8TB
then it doesn’t have—as I already said—a distance property.
Mar 3 '14 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

8 posts views Thread by Fendi Baba | last post: by
15 posts views Thread by waltbrad | last post: by
1 post views Thread by ANDRE BERTONHA | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.