0

I got problem that function do not return created objects. What I have to do if I want that variable "test" will be the same object that was created?

     var test = runSnapToRoad(path);    // pass data to function
     console.log(test);                 // return "undefined"


         function runSnapToRoad(path) {
           snappedPath = [];
            var pathValues = [];
            for (var i = 0; i < path.getLength(); i++) {
              pathValues.push(path.getAt(i).toUrlValue());
            }

            $.get('https://roads.googleapis.com/v1/snapToRoads', {
              interpolate: true,
              key: apiKey,
              path: pathValues.join('|')
            }, function (data) {
              $.each( data.snappedPoints, function( key, value ) {


                var myObj = {
                  "lng" : value.location.longitude,    
                  "lat" : value.location.latitude  
                };

                snappedPath.push( myObj );

              });

              console.log(snappedPath); // until here everything is ok, I got [Object, Object] with objects inside

              return snappedPath; // 
            });
Marius
  • 1

0 Answers0