I am using the DirectionsDisplay returned by the Google Map JS APIv3 to get the coordinates of some locations. There are functions in DirectionsDisplay for returning values ( lat()and lng()), but I need to send them to PHP, serialized JSON.stringify, so I assign values to new variables ( cLatand 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 cLatand 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
cLon: 14.148118999999951
lat: function()
lng: function()
__proto__: _.L
...
However, it console.log(JSON.stringify(steps))displays the following:
{
"steps":[
{
"distance":{
"text":"132 km",
"value":132266
},
"duration":{
"text":"1 hodín, 34 minút",
"value":5639
},
"end_location":{
"lat":64.49756909999999,
"lng":14.148118999999951
},
...
}
]
}
What am I doing wrong?
source
share