javascript - Getting value from a JSON -
i have json --
.... "location" : { "lat" : 37.42140090, "lng" : -122.08537010 }, ....
i trying access lat , lng values. how can it?
my code
results[0].geometry.location.lat or results[0].geometry.location.lng
does not work. output when use results[0].geometry.location .
the json using -- http://maps.googleapis.com/maps/api/geocode/json?address=1600+amphitheatre+parkway,+mountain+view,+ca&sensor=true
update --
this how making request api
geocoder.geocode( { 'address': search_addr}, function(results, status) { if (status == google.maps.geocoderstatus.ok) { var t = results[0].geometry.location.lat; } else { alert('geocode not successful following reason: ' + status); }
thanks
when using google's javascript apis, you're not typically interacting parsed json directly, rather wrapper object
s.
specifically, results[0].geometry.location
instance of google.maps.latlng
. so, instead of holding values themselves, lat
, lng
methods return
values:
var geoloc = results[0].geometry.location; var lat = geoloc.lat(); var lng = geoloc.lng();
Comments
Post a Comment