Assign local variable to JSON object

#1

Hello team!

In short, can I asign the value of a variable float, at the time of defining a local JSON object??
e.g.

var x = 3.5; $scope.MySquare = { side: x }

Now I will share what I want to do, less simple than that. I’m working with coordinates with $cordovaGeolocation and I do the following:

  `  $scope.latScope = position.coords.latitude;`

or
var latVar =position.coords.latitude;

Both work, because they show their content, when i do console.log()

Now I wanna set a Marker, a pinpoint on a map, instantiated like this:

markers : {
              ME: {   
                  lat: 36.3636,
                  lng: -7.2727
               }
}

Ok, and it works! (yay!) but the thing is that I dont want to assign the float number to the lat and lng atributes of this small JSON. I want to asign

markers : {
              ME: {   
                  lat: latVar, (or $scope.latScope)
                  lng:  lngVar, (or $scope.lngScope)
               }
}

The value within these variables. With writen float numbers works, but not when asigning variables.

A bit of light over here? Thanks in advance!

#2

ehm could you show us the complete codeblock of that? assign variables to an object is a standard functionality and should work.

I would assume that you have a problem with async code. because the geolocation plugin return the coords async and you will not wait for it, when you set your marker :wink: