Solved

Return a value

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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
CTAs encourage people to do something specific to show interest in your company, product or service. Keep reading to learn why CTAs should always be thought of as extremely important, albeit small, sections of websites.
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 benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

705 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