1

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

[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 并将传感器参数设置为 true,但结果始终相同。

4

0 回答 0