I am using the Google Geocoding API v3[1] from an iOS application but can’t get it to return a gzip response. The v2 was much more lightweight but with v3 I’m getting a ~20kb JSON response .. which might take some time to retrieve on a bad GPRS connection, so I would really like to get a gzipped result back.
Am I wondering if I’m doing anything wrong in my call or if their API really doesn’t support gzip or deflate. It just sounds strange to me.
This is a what I’m doing in my code:
NSURL *url = [NSURL URLWithString:@"http://maps.googleapis.com/maps/api/geocode/json?latlng=55,12&sensor=true"];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:url];
[req setValue:@"gzip,deflate" forHTTPHeaderField:@"Accept-Encoding"];
NSURLConnection *c = [[NSURLConnection alloc]
initWithRequest:req delegate:self startImmediately:YES];
I’ve tried with only “gzip” and “deflate” too. Same result.
[1] http://code.google.com/apis/maps/documentation/geocoding/
I have no idea why, but it seems to have something to do with the
User-Agentheader. When I request the API page with Firefox (Mozilla/5.0 (Windows NT 6.1; WOW64; rv:10.0.2) Gecko/20100101 Firefox/10.0.2) I get a gzipped response. When I request the page with cURL (specifically asking for a compressed response), I get a plain response. However, if I override cURL’s default agent to the Mozilla one, I do get a compressed response.