我是iOS新手,所以如果有任何幫助,將不勝感激。 我想從地址獲取經度和緯度,早些時候代碼工作正常,但現在JSON數據將變爲空。在iOS的經度和緯度的谷歌查詢沒有得到json響應?
這裏我的示例代碼,
url = [NSString stringWithFormat:@"http://maps.google.com/maps/api/geocode/json?address=%@&sensor=false",appDelegate.sAddress];
url=[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Address URL: %@",url);
//Formulate the string as a URL object.
NSURL *requestURL=[NSURL URLWithString:url];
NSData* data = [NSData dataWithContentsOfURL: requestURL];
NSString *returnString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"my Coordinate : %@",returnString);
NSError* error;
NSDictionary* json = [NSJSONSerialization
JSONObjectWithData:data
options:kNilOptions
error:&error];
但我得到的輸出爲空。
所以請幫助我。
謝謝!
考慮使用[CLGeocoder類](https://developer.apple.com/library/ios/#documentation/CoreLocation/Reference/CLGeocoder_class/Reference/Reference.html),而不是手動直接查詢。 – Anna