Google で住所を検索して、その住所の緯度と経度を返そうとしています。私はほとんどそこにいます= D
問題は..巨大なjsonが戻ってきて、緯度と経度だけを取得する方法がわかりません。
私は AFNetworking を使用しています。
//Build the string to Query Google Maps.
NSMutableString *urlString = [NSMutableString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false", address];
//Replace Spaces with a '+' character.
[urlString setString:[urlString stringByReplacingOccurrencesOfString:@" " withString:@"+"]];
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
AFJSONRequestOperation *operation = [AFJSONRequestOperation JSONRequestOperationWithRequest:request success:^(NSURLRequest *request, NSHTTPURLResponse *response, id JSON) {
//NSLog(@"minha location %@", JSON);
//NSLog(@"minha url %@", urlString);
NSArray *resul = [[NSArray alloc] init];
resultado = [JSON objectForKey:@"results"];
NSLog(@"Resultado: %@", result);
これを使用すると、次のようになります。
2013-04-19 08:04:57.092 XePop[7011:907] Result: (
{
"address_components" = (
{
"long_name" = 379;
"short_name" = 379;
types = (
"street_number"
);
},
{
"long_name" = "Rua Domingos Ol\U00edmpio";
"short_name" = "R. Domingos Ol\U00edmpio";
types = (
route
);
},
{
"long_name" = Centro;
"short_name" = Centro;
types = (
sublocality,
political
);
},
{
"long_name" = Sobral;
"short_name" = Sobral;
types = (
locality,
political
);
},
{
"long_name" = "Cear\U00e1";
"short_name" = CE;
types = (
"administrative_area_level_1",
political
);
},
{
"long_name" = "Rep\U00fablica Federativa do Brasil";
"short_name" = BR;
types = (
country,
political
);
},
{
"long_name" = "62011-140";
"short_name" = "62011-140";
types = (
"postal_code"
);
}
);
"formatted_address" = "Rua Domingos Ol\U00edmpio, 379 - Centro, Sobral - CE, 62011-140, Rep\U00fablica Federativa do Brasil";
geometry = {
bounds = {
northeast = {
lat = "-3.6878671";
lng = "-40.35096009999999";
};
southwest = {
lat = "-3.6878797";
lng = "-40.35097349999999";
};
};
location = {
lat = "-3.6878797";
lng = "-40.35097349999999";
};
"location_type" = "RANGE_INTERPOLATED";
viewport = {
northeast = {
lat = "-3.686524419708497";
lng = "-40.3496178197085";
};
southwest = {
lat = "-3.689222380291502";
lng = "-40.35231578029149";
};
};
};
types = (
"street_address"
);
}
)
How Can I get only the Location Part, which has:
location = {
lat = "-3.6878797";
lng = "-40.35097349999999";
};
[JSON objectForKey:@"location"] を試しましたが、null が返されます。
私を助けてください。
ご検討をお願いいたします。