向Google Place API添加地点的问题

时间:2013-01-22 05:53:31

标签: ios objective-c google-api

我有一个要添加到字典中的位置数据

[latLong setObject:@"33.6667" forKey:@"lat"];
[latLong setObject:@"73.1667" forKey:@"lng"];
[locDict setObject:latLong forKey:@"location"];
[locDict setObject:@"50" forKey:@"accuracy"];
[locDict setObject:@"Conve" forKey:@"name"];
[locDict setObject:[NSArray arrayWithObjects:@"moving_company", @"general_contractor", nil] forKey:@"types"];
[locDict setObject:@"en" forKey:@"language"];

然后我从帖子请求中创建JSON数据

NSString *jsonRequest = [locDict JSONRepresentation];
NSData *requestData= [jsonRequest dataUsingEncoding:NSUTF8StringEncoding];    


NSString *urlString = @"https://maps.googleapis.com/maps/api/place/add/json&sensor=false&key=AIzaSyDrGuhso6MRdEmnvAMa-e4iMQuYo";  //key altered
NSString *encodedUrl = [urlString stringByAddingPercentEscapesUsingEncoding: NSUTF8StringEncoding];
NSMutableURLRequest *req = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:encodedUrl]];
[req setHTTPMethod:@"POST"];
[req setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[req setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
[req setValue:[NSString stringWithFormat:@"%d", [requestData length]] forHTTPHeaderField:@"Content-Length"];
[req setHTTPBody:requestData];
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:req delegate:self];

它总是给我404错误。我已经尝试使用lat-lng from device并将sensor参数设置为true,但结果始终相同。

0 个答案:

没有答案