2013-03-19 1 views
2

나는 IOS를 처음 사용합니다. Google 지역 정보에 새로운 장소를 추가해야합니다. 이 링크 https://developers.google.com/places/documentation/actions을 클릭하여 버튼 클릭 위치를 추가했지만이 매개 변수를 전달하는 것에 대해 혼란스러워합니다. 나는 마침내 성공적으로 실행 내 코드 & 변경에 따라 만든Google 지역 정보에 새 장소 추가

NSString *lat [email protected]"-33.8669710"; 
NSString *longt [email protected]"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]; 
+0

@iPatel Google Places – Kalyani

+0

예제 코드 아래에 정확한 질문을 입력해야한다고 생각합니다. 정확히 어떤 매개 변수 나 방법이 당신을 혼란스럽게합니까? –

+0

Post 메서드 형식이 필요한 링크에 매개 변수를 전달하는 방법이 혼란 스럽습니다. – Kalyani

답변

3

...

//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); 

& 다음 내가 디코딩 한 수익을 :

내 코딩 라인

페치이 같다 응답을 나는 괜찮아 ...... ......

위의 코드를 사용할 수 있습니다. 도움이 필요하면 누구나 분명히 할 수 있습니다. ask .... :)

관련 문제