views:

156

answers:

1

I'm using Google maps with KML Query. But my query string is "Japanese" string "マクドナルド" I'm using http://maps.google.co.jp. When requesting data, I'm getting "0" bytes. But the same query when I put in browser, its download a KML file. My code is as follows:

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];

I'm receiving "myData" with 0 bytes. why?

A: 

You need to URLencode the japanese text. A browser usually automatically encodes text for you, but NSURL won't.

Try something like

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