Vandervidi
Vandervidi

Reputation: 295

Parsing google maps Json file

i have this Json file and im trying to access some parameters with jquery getJSON.

This is the Json file:

{
"results" : [
  {
     "address_components" : [
        {
           "long_name" : "croatia",
           "short_name" : "HR",
           "types" : [ "country", "political" ]
        }
     ],
     "formatted_address" : "croatia",
     "geometry" : {
        "bounds" : {
           "northeast" : {
              "lat" : 46.5552234,
              "lng" : 19.4480523
           },
           "southwest" : {
              "lat" : 42.3922652,
              "lng" : 13.4896912
           }
        },
        "location" : {
           "lat" : 45.1,
           "lng" : 15.2
        },
        "location_type" : "APPROXIMATE",
        "viewport" : {
           "northeast" : {
              "lat" : 46.5552234,
              "lng" : 19.4480523
           },
           "southwest" : {
              "lat" : 42.3923464,
              "lng" : 13.4896912
           }
        }
     },
     "types" : [ "country", "political" ]
  }
],
"status" : "OK"
}

and this is the jquery code

$.getJSON('SOME JSON FILE', function(data) {
    var output="<ul>";

        output+="<li>" + **data.results[geometry].location.lat** + " " + "</li>";


    output+="</ul>";
    document.getElementById("placeholder").innerHTML=output;

});

What did i do wrong and can you help me access the location->lat parameter?

Upvotes: 0

Views: 85

Answers (1)

Sambath Kumar S
Sambath Kumar S

Reputation: 407

you made some mistake in**data.results[geometry].location.lat** this may formatting mistake

Hi this code may help you

 $.getJSON('SOME JSON FILE', function (data) {
            $.each(data.results, function (i, f) {
                var output = "<ul>";
                output += "<li>" + f.geometry.location.lat + " " + "</li>";
                output += "</ul>";
                document.getElementById("placeholder").innerHTML = output;
            });
        });

Upvotes: 2

Related Questions