我使用了谷歌的自动完成地点搜索API,它工作得很好。
但是在响应中,谷歌没有返回地点的“纬度和经度”信息。
我的代码如下
NSString *strUrl =
[[[NSString stringWithFormat:@"%@%@%@?sensor=false&key=%@&input=%@",
PLACES_API_BASE,
TYPE_AUTOCOMPLETE,
OUT_JSON,API_KEY,
txt_search.text]
stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]
stringByReplacingOccurrencesOfString:@" " withString:@"%20"];
NSLog(@"--- address --- %@",strUrl);
NSData *responseData = [NSData dataWithContentsOfURL:[NSURL URLWithString:strUrl] options:NSDataReadingUncached error:nil];
NSDictionary *dictResponse = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:Nil];
NSLog(@"%@",dictResponse);
响应
{
"status": "OK",
"predictions": [ {
"description": "Paris, France",
"id" : "691b237b0322f28988f3ce03e321ff72a12167fd",
"reference": "CiQYAAAA0Q_JA...kT3ufVLDDvTQsOwZ_tc",
"terms": [ {
"value": "Paris",
"offset": 0
}, {
"value": "France",
"offset": 7
} ],
"types": [ "geocode" ],
"matched_substrings": [ {
"offset": 0,
"length": 5
} ]
}