Solved

# Return a value

Posted on 2012-03-20
Medium Priority
276 Views
I'm using Google Maps API to do this
``````function getDist() {
service.getDistanceMatrix(
{
origins: [origin1, origin2],
destinations: [destinationA, destinationB],
avoidHighways: false,
avoidTolls: false
}, callback);
}

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

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

LVL 14

Expert Comment

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

ID: 37744095
I am using the Google Maps API to calculate driving distance.
0

LVL 14

Expert Comment

ID: 37744167
0

Author Comment

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

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);
}
}
``````
0

## Featured Post

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

How do you create a user-centered user experience on your website? And what are some things you should consider in the process?
There is a wide range of advantages associated with the use of ASP.NET. This is why this programming framework is used to create excellent enterprise-class websites, technologies, and web applications.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).
###### Suggested Courses
Course of the Month6 days, 11 hours left to enroll