Which latitude and longitude has to taken?

101 views Asked by At

I am getting the following response for this API "http://maps.google.com/maps/api/geocode/json?sensor=false&address=No.3C-137,2nd Floor,2nd Main Rd, Kasturi Nagar, East of NGEF Layout, Bennigana Halli, Bengaluru, Karnataka 560043 "

For his address "No.3C-137, 2nd Floor, 2nd Main Rd, Kasturi Nagar, East of NGEF Layout, Bennigana Halli, Bengaluru, Karnataka 560043 " I want to extract latitude and longitude. There are many number of address_components there. which addresscompont has to be consider and which latitude and longitude has to be taken i.e northeast,southwest,location.

 Printing description of dict:
        {
            results =     (
                        {
                    "address_components" =             (
                                        {
                            "long_name" = 137;
                            "short_name" = 137;
                            types =                     (
                                "street_number"
                            );
                        },
                                        {
                            "long_name" = "2nd Main Road";
                            "short_name" = "2nd Main Rd";
                            types =                     (
                                route
                            );
                        },
                                        {
                            "long_name" = "East of NGEF Layout";
                            "short_name" = "East of NGEF Layout";
                            types =                     (
                                "sublocality_level_2",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bennigana Halli";
                            "short_name" = "Bennigana Halli";
                            types =                     (
                                "sublocality_level_1",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = Bengaluru;
                            "short_name" = Bengaluru;
                            types =                     (
                                locality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bangalore Urban";
                            "short_name" = "Bangalore Urban";
                            types =                     (
                                "administrative_area_level_2",
                                political
                            );
                        },
                                        {
                            "long_name" = Karnataka;
                            "short_name" = KA;
                            types =                     (
                                "administrative_area_level_1",
                                political
                            );
                        },
                                        {
                            "long_name" = India;
                            "short_name" = IN;
                            types =                     (
                                country,
                                political
                            );
                        },
                                        {
                            "long_name" = 560043;
                            "short_name" = 560043;
                            types =                     (
                                "postal_code"
                            );
                        }
                    );
                    "formatted_address" = "137, 2nd Main Road, East of NGEF Layout, Bennigana Halli, Bengaluru, Karnataka 560043, India";
                    geometry =             {
                        bounds =                 {
                            northeast =                     {
                                lat = "13.0048165";
                                lng = "77.6600505";
                            };
                            southwest =                     {
                                lat = "13.004809";
                                lng = "77.66003379999999";
                            };
                        };
                        location =                 {
                            lat = "13.0048165";
                            lng = "77.6600505";
                        };
                        "location_type" = "RANGE_INTERPOLATED";
                        viewport =                 {
                            northeast =                     {
                                lat = "13.0061617302915";
                                lng = "77.66139113029149";
                            };
                            southwest =                     {
                                lat = "13.0034637697085";
                                lng = "77.65869316970849";
                            };
                        };
                    };
                    "partial_match" = 1;
                    "place_id" = ElwxMzcsIDJuZCBNYWluIFJvYWQsIEVhc3Qgb2YgTkdFRiBMYXlvdXQsIEJlbm5pZ2FuYSBIYWxsaSwgQmVuZ2FsdXJ1LCBLYXJuYXRha2EgNTYwMDQzLCBJbmRpYQ;
                    types =             (
                        "street_address"
                    );
                },
                        {
                    "address_components" =             (
                                        {
                            "long_name" = 137;
                            "short_name" = 137;
                            types =                     (
                                "street_number"
                            );
                        },
                                        {
                            "long_name" = "2nd H Main Road";
                            "short_name" = "2nd H Main Rd";
                            types =                     (
                                route
                            );
                        },
                                        {
                            "long_name" = "Kasturi Nagar";
                            "short_name" = "Kasturi Nagar";
                            types =                     (
                                "sublocality_level_2",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bennigana Halli";
                            "short_name" = "Bennigana Halli";
                            types =                     (
                                "sublocality_level_1",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = Bengaluru;
                            "short_name" = Bengaluru;
                            types =                     (
                                locality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bangalore Urban";
                            "short_name" = "Bangalore Urban";
                            types =                     (
                                "administrative_area_level_2",
                                political
                            );
                        },
                                        {
                            "long_name" = Karnataka;
                            "short_name" = KA;
                            types =                     (
                                "administrative_area_level_1",
                                political
                            );
                        },
                                        {
                            "long_name" = India;
                            "short_name" = IN;
                            types =                     (
                                country,
                                political
                            );
                        },
                                        {
                            "long_name" = 560043;
                            "short_name" = 560043;
                            types =                     (
                                "postal_code"
                            );
                        }
                    );
                    "formatted_address" = "137, 2nd H Main Road, Kasturi Nagar, Bennigana Halli, Bengaluru, Karnataka 560043, India";
                    geometry =             {
                        bounds =                 {
                            northeast =                     {
                                lat = "13.0025809";
                                lng = "77.6626708";
                            };
                            southwest =                     {
                                lat = "13.0025795";
                                lng = "77.6626524";
                            };
                        };
                        location =                 {
                            lat = "13.0025809";
                            lng = "77.6626708";
                        };
                        "location_type" = "RANGE_INTERPOLATED";
                        viewport =                 {
                            northeast =                     {
                                lat = "13.0039291802915";
                                lng = "77.6640105802915";
                            };
                            southwest =                     {
                                lat = "13.0012312197085";
                                lng = "77.6613126197085";
                            };
                        };
                    };
                    "partial_match" = 1;
                    "place_id" = ElgxMzcsIDJuZCBIIE1haW4gUm9hZCwgS2FzdHVyaSBOYWdhciwgQmVubmlnYW5hIEhhbGxpLCBCZW5nYWx1cnUsIEthcm5hdGFrYSA1NjAwNDMsIEluZGlh;
                    types =             (
                        "street_address"
                    );
                },
                        {
                    "address_components" =             (
                                        {
                            "long_name" = 137;
                            "short_name" = 137;
                            types =                     (
                                "street_number"
                            );
                        },
                                        {
                            "long_name" = "2nd A Main Road";
                            "short_name" = "2nd A Main Rd";
                            types =                     (
                                route
                            );
                        },
                                        {
                            "long_name" = "B Channasandra";
                            "short_name" = "B Channasandra";
                            types =                     (
                                "sublocality_level_3",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Kasturi Nagar";
                            "short_name" = "Kasturi Nagar";
                            types =                     (
                                "sublocality_level_2",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bennigana Halli";
                            "short_name" = "Bennigana Halli";
                            types =                     (
                                "sublocality_level_1",
                                sublocality,
                                political
                            );
                        },
                                        {
                            "long_name" = Bengaluru;
                            "short_name" = Bengaluru;
                            types =                     (
                                locality,
                                political
                            );
                        },
                                        {
                            "long_name" = "Bangalore Urban";
                            "short_name" = "Bangalore Urban";
                            types =                     (
                                "administrative_area_level_2",
                                political
                            );
                        },
                                        {
                            "long_name" = Karnataka;
                            "short_name" = KA;
                            types =                     (
                                "administrative_area_level_1",
                                political
                            );
                        },
                                        {
                            "long_name" = India;
                            "short_name" = IN;
                            types =                     (
                                country,
                                political
                            );
                        },
                                        {
                            "long_name" = 560043;
                            "short_name" = 560043;
                            types =                     (
                                "postal_code"
                            );
                        }
                    );

  "formatted_address" : "137, 2nd H Main Road, Kasturi Nagar, Bennigana Halli, Bengaluru, Karnataka 560043, India",
         "geometry" : {
            "bounds" : {
               "northeast" : {
                  "lat" : 13.0025809,
                  "lng" : 77.6626708
               },
               "southwest" : {
                  "lat" : 13.0025795,
                  "lng" : 77.6626524
               }
            },
            "location" : {
               "lat" : 13.0025809,
               "lng" : 77.6626708
            },
            "location_type" : "RANGE_INTERPOLATED",
            "viewport" : {
               "northeast" : {
                  "lat" : 13.0039291802915,
                  "lng" : 77.6640105802915
               },
               "southwest" : {
                  "lat" : 13.0012312197085,
                  "lng" : 77.6613126197085
               }
            }
         },
         "partial_match" : true,
         "place_id" : "ElgxMzcsIDJuZCBIIE1haW4gUm9hZCwgS2FzdHVyaSBOYWdhciwgQmVubmlnYW5hIEhhbGxpLCBCZW5nYWx1cnUsIEthcm5hdGFrYSA1NjAwNDMsIEluZGlh",
         "types" : [ "street_address" ]
      },
1

There are 1 answers

8
Blind Ninja On

This one the value with key location

location = { lat = "13.0048165"; lng = "77.6600505"; };

The provide data is a Dictionary (with key results). Derived value from results is an array which holds all possible places from API. Each place (an object at index of array) is dictionary which have a sub Dictionary with key geometry. In this dictionary you have another dictionary which hold your location dictionary with lat and lng.

if i am not wrong it will be something like this

NSDictionary *aPlace=[[dict objectForKey:@"results"] objectAtIndex:someIndex];
NSDictionary *geomatry=[aPlace objectForKey:@"geometry"];
NSDictionary *location=[geomatry objectForKey:@"location"];
float lat=[[location objectForKey:@"lat"] floatValue ];
float lng=[[location objectForKey:@"lng"] floatValue ];