将新地点添加到Google地方信息 [英] Add new place to Google Places

查看:77
本文介绍了将新地点添加到Google地方信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是IOS的新手.我必须将新地点添加到Google地方信息.我已引用此链接 https://developers.google.com/places/documentation/actions在按钮单击上添加一个位置,但是我对此传递参数感到困惑.

I am new to IOS. I have to add new places to Google Places. I have referred this link https://developers.google.com/places/documentation/actions to add a place on button click, but I'm confused about passing parameters for this.

我的编码行是这样提取的:

My coding lines are like this to fetch:

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

推荐答案

我对代码&终于成功执行了...

I have made following changes to my code & finally it is executed successfully...

//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 ......:)

& then i have decoded return response which i get i status as OK......:)

任何人都可以使用以上代码...如果有任何帮助,您可以肯定地询问....:)

Any one can use above code...if any help require you can surely ask....:)

这篇关于将新地点添加到Google地方信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆