Solved

Return a value

Posted on 2012-03-20
5
267 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
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 500 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

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Color can increase conversions, create feelings of warmth or even incite people to get behind a cause. If you want your website to really impact site visitors, then it is vital to consider the impact color has on them.
Although a lot of people devote their energy toward marketing for specific industries, there are some basic principles that can be applied to any sector imaginable. We’ll look at four steps to take and examine how those steps were put into action fo…
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…

696 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