?
Solved

Return a value

Posted on 2012-03-20
5
Medium Priority
?
271 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 14

Expert Comment

by:nishant joshi
ID: 37744020
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
ID: 37744095
I am using the Google Maps API to calculate driving distance.
0
 
LVL 14

Expert Comment

by:nishant joshi
ID: 37744167
0
 

Author Comment

by:dshrenik
ID: 37744193
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 1000 total points
ID: 37744250
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

770 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