loop through JSON with .getJSON and $.each
Hi jQuery folks
First question - how you debug in Jquery, i am getting crazy because firebug doesn't give me a response on code lines...
I am trying to get the latitude and longitude from a json structure which i got over this google maps geoencode api (v3) - 2 addresses -> it looks like this....
[{"status":"OK","results":[{"types":["street_address"],"formatted_address":"Moserhofgasse 36, 8010 Graz, Austria","address_components":[{"long_name":"36","short_name":"36","types":["street_number"]},{"long_name":"Moserhofgasse","short_name":"Moserhofgasse","types":["route"]},{"long_name":"Jakomini","short_name":"Jakomini","types":["sublocality","political"]},{"long_name":"Graz","short_name":"Graz","types":["locality","political"]},{"long_name":"Graz","short_name":"Graz","types":["administrative_area_level_2","political"]},{"long_name":"Steiermark","short_name":"Stmk.","types":["administrative_area_level_1","political"]},{"long_name":"Austria","short_name":"AT","types":["country","political"]},{"long_name":"8010","short_name":"8010","types":["postal_code"]}],"geometry":{"location":{"lat":47.0609404,"lng":15.4545919},"location_type":"ROOFTOP","viewport":{"southwest":{"lat":47.0577928,"lng":15.4514443},"northeast":{"lat":47.064088,"lng":15.4577395}}}}]},{"status":"OK","results":[{"types":["locality","political"],"formatted_address":"Hermosa, SD 57744, USA","address_components":[{"long_name":"Hermosa","short_name":"Hermosa","types":["locality","political"]},{"long_name":"Custer","short_name":"Custer","types":["administrative_area_level_2","political"]},{"long_name":"South Dakota","short_name":"SD","types":["administrative_area_level_1","political"]},{"long_name":"United States","short_name":"US","types":["country","political"]},{"long_name":"57744","short_name":"57744","types":["postal_code"]}],"geometry":{"location":{"lat":43.8397124,"lng":-103.19102},"location_type":"APPROXIMATE","viewport":{"southwest":{"lat":43.8316638,"lng":-103.207028},"northeast":{"lat":43.8477599,"lng":-103.175013}},"bounds":{"southwest":{"lat":43.832473,"lng":-103.204458},"northeast":{"lat":43.843202,"lng":-103.184137}}}}]}]
i tried it this way:
jQuery(function($) {
$.getJSON("test1.php",function(json){
$.each(json.results function(i, lat) {
src = results.geometry.location.lat
alert ( src ) });
});
});
i am close ? or far aways ?
thx in advance
Martin