我一直在尝试在 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。
请帮帮我。
谢谢您的考虑。