I am using DirectionsDisplay returned by Google Map JS APIv3 to get coordinates of some locations. The DirectionsDisplay has functions to return the values (lat() and lng()) but I need to send them to PHP serialized by JSON.stringify so I assign the values to new variables (cLat and cLon):
var steps=directionsDisplay.getDirections().routes[0].legs[0].steps;
for(var i=0;i<steps.length;i++){
steps[i].end_location.cLat = steps[i].end_location.lat();
steps[i].end_location.cLon = steps[i].end_location.lng();
}
console.log(steps) displays cLat and cLon as expected:
Object {steps: Array[8]}
steps: Array[8]
0: Object
distance: Object
duration: Object
encoded_lat_lngs: "..."
end_location: _.L
cLat: 64.49756909999999 //here
cLon: 14.148118999999951 //here
lat: function()
lng: function()
__proto__: _.L
...
However, console.log(JSON.stringify(steps)) displays this:
{
"steps":[
{
"distance":{
"text":"132 km",
"value":132266
},
"duration":{
"text":"1 hodín, 34 minút",
"value":5639
},
"end_location":{
"lat":64.49756909999999, //here
"lng":14.148118999999951 //here
},
...
}
]
}
What am I doing wrong?