Bill Noble Bill Noble - 1 month ago 9
Javascript Question

JSON parsing incorrectly

I am trying to extract data from the result of a Google Places call.

If I run the following Javascript:

alert(JSON.stringify(places[0].geometry.location));


I get the following output, as expected:

{"lat":59.9138688,"lng":10.752245399999993}


However if I put .lat on the end to extract the lat value and run:

alert(JSON.stringify(places[0].geometry.location.lat));


I get:

undefined


And if I run the alert without the JSON.stringify as follows:

alert(places[0].geometry.location.lat);


I get:

function (){return a}


What am I doing wrong?

Answer

You must do this:

alert(places[0].geometry.location.lat());