对于这个API,我得到以下回复“http://maps.google.com/maps/api/geocode/json?sensor=false&address=No.3C-137,2nd地板,第二主干道,KASTuri Nagar,NGEF布局东部,Bennigana Halli,班加罗尔,卡纳塔克邦560043”
他的地址“NGEF布局东部Kasturi Nagar第二大道2楼3C-137号,Bennigana Halli,班加罗尔,卡纳塔克邦560043”我想提取纬度和经度。那里有许多address_components。必须考虑哪个地址,必须考虑哪个纬度和经度,即东北,西南,地区。
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" ]
},
答案 0 :(得分:0)
这是带有键location
location = {
lat = "13.0048165";
lng = "77.6600505";
};
提供数据是一个字典(带有键results
)。来自results
的派生值是一个包含API所有可能位置的数组。每个地方(数组索引处的对象)是具有键geometry
的子词典的字典。在这本词典中,您有另一本字典,其中包含location
字典lat
和lng
。
如果我没有错,那将会是这样的
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 ];