我正在使用带有KML查询的Google地图。但我的查询字符串是“日语”字符串“マクドナルド” 我正在使用http://maps.google.co.jp。 在请求数据时,我得到“0”字节。但是当我放入浏览器时,同样的查询,它下载一个KML文件。我的代码如下:
query = [NSString stringWithFormat:@"http://maps.google.co.jp/maps?&near=%f,%f&q=マクドナルド&output=kml&num=%d", lat,lon, num];
NSURL * url = [NSURL URLWithString:query]; NSURLRequest * request = [NSURLRequest requestWithURL:url]; NSLog(@“Quering URL =%@”,url);
NSHTTPURLResponse *response = [[NSHTTPURLResponse alloc] autorelease];
NSData *myData = [NSURLConnection sendSynchronousRequest:request returningResponse: &response error: nil ];
NSInteger errorcode = [response statusCode];
我收到0字节的“myData”。为什么呢?
答案 0 :(得分:0)
您需要对日文文本进行URL编码。浏览器通常会自动为您编码文本,但NSURL不会。
尝试类似
的内容NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unencodedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );