Solved

Return a value

Posted on 2012-03-20
5
260 Views
Last Modified: 2012-08-13
I'm using Google Maps API to do this
function getDist() {
var service = new google.maps.DistanceMatrixService();
service.getDistanceMatrix(
  {
    origins: [origin1, origin2],
    destinations: [destinationA, destinationB],
    travelMode: google.maps.TravelMode.DRIVING,
    avoidHighways: false,
    avoidTolls: false
  }, callback);
}

function callback(response, status) {
  // See Parsing the Results for
  // the basics of a callback function.
}

Open in new window


However, I need to return a value from the function getDist(). Please let me know how I can do this. Thanks!
0
Comment
Question by:dshrenik
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:nishant joshi
Comment Utility
might you can use direct calculation

 Math.sqrt((desA-Origin1)*(desA-Origin1)+(desB-Origin2)*(desB-Origin2))

whatever the result is your direct distance.

the formula is use in this is the line equation.....


Regards,
nishant
0
 

Author Comment

by:dshrenik
Comment Utility
I am using the Google Maps API to calculate driving distance.
0
 
LVL 14

Expert Comment

by:nishant joshi
Comment Utility
0
 

Author Comment

by:dshrenik
Comment Utility
I have the code that calculates the distance. Its just that I want to return the value rather than just printing it or displaying it in an alert.
0
 
LVL 14

Accepted Solution

by:
nishant joshi earned 500 total points
Comment Utility
var distance=0
for (var i = 0; i < origins.length; i++) { 
        var results = response.rows[i].elements; 
        for (var j = 0; j < results.length; j++) { 
           distance=distance+parseInt(results[j].distance.text); 
        } 
      }

Open in new window

0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Use these top 10 tips to master the art of email signature design. Create an email signature design that will easily wow recipients, promote your brand and highlight your professionalism.
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo‚Ķ
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now