gpt4 book ai didi

iphone - 向 Google 地方信息添加新地点

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:11:02 26 4
gpt4 key购买 nike

我是 IOS 新手。我必须向 Google Places 添加新地点。我已经提到了这个链接 https://developers.google.com/places/documentation/actions在单击按钮时添加一个位置,但我对为此传递参数感到困惑。

我的代码行是这样获取的:

NSString *lat =@"-33.8669710";
NSString *longt =@"151.1957362";
gKey = @"my api key";

NSString *placeString = [NSString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/add/json?sensor=false&key=%@HTTP/1.1Host:maps.googleapis.com {\"location\":{\"lat\":%@,\"lng\":%@},\"accuracy\": 50,\"name\":\"Gimmy Pet Store!\",\"types\":[\"pet_store\"],\"language\":\"en-AU\"}",gKey,lat,longt];

placeString = [placeString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSLog(@"Main Place Url: %@",placeString);
NSURL *placeURL = [NSURL URLWithString:placeString];

NSMutableURLRequest *request=[NSMutableURLRequest requestWithURL:placeURL];

[request setHTTPMethod:@"POST"];

NSURLConnection *placesConn =[[NSURLConnection alloc] initWithRequest:request delegate:self];

最佳答案

我对我的代码进行了以下更改并最终成功执行...

//for setting Parameters to post the url.just change tag values to below line...

NSString *str1 = [NSString stringWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><PlaceAddRequest><location><lat>your latitude</lat><lng>your longitude</lng></location><accuracy>50</accuracy><name>place name</name><type>supported type</type><language>en-US</language></PlaceAddRequest>"];
NSLog(@"str1=====%@",str1);

NSString *str2 = [str1 stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];

NSData *requestdata = [NSData dataWithBytes:[str2 UTF8String] length:[str2 length]];
NSString *postLength = [NSString stringWithFormat:@"%d", [requestdata length]];

//requesting main url to add new place to google places
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"https://maps.googleapis.com/maps/api/place/add/xml?sensor=false&key=your api key"]];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];

[request setHTTPMethod:@"POST"];
[request setHTTPBody:[NSData dataWithBytes:[str1 UTF8String] length:[str1 length]]];

//NSURLConnection *placesConn =[[NSURLConnection alloc] initWithRequest:request delegate:self];
NSData *returndata = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSString *returnstr = [[[NSString alloc] initWithData:returndata encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"returnstr: %@",returnstr);

& 然后我解码了返回响应,我的状态为 OK ......:)

任何人都可以使用上面的代码......如果需要任何帮助,你一定可以问......:)

关于iphone - 向 Google 地方信息添加新地点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15493283/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com