iPhone谷歌地图KML搜索

时间:2010-04-28 09:48:59

标签: iphone google-maps kml

我正在使用带有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”。为什么呢?

1 个答案:

答案 0 :(得分:0)

您需要对日文文本进行URL编码。浏览器通常会自动为您编码文本,但NSURL不会。

尝试类似

的内容
NSString * encodedString = (NSString *)CFURLCreateStringByAddingPercentEscapes(
    NULL,
    (CFStringRef)unencodedString,
    NULL,
    (CFStringRef)@"!*'();:@&=+$,/?%#[]",
    kCFStringEncodingUTF8 );