如何设置谷歌地点的自动完成请求到iOS中的UITextField [英] How to set the google places Autocomplete Requests to a UITextField in iOS
本文介绍了如何设置谷歌地点的自动完成请求到iOS中的UITextField的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我是iOS编程新手。我的要求是将Google地方的自动填充请求设置为 UITextField
。
我写了下面的代码:
NSString * urlPath = [NSString stringWithFormat:@/ maps / api / place /自动填充/ JSON输入=%@&安培;类型=地理编码及安培;语言= EN-EN&安培;传感器=假,串];
NSURL * url = [[NSURL alloc] initWithScheme:@httphost:@maps.googleapis.compath:urlPath];
NSLog(@url is :::%@,url);
NSMutableURLRequest * request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@POST];
NSURLResponse *回应;
NSError *错误;
NSData *数据;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:& response error:& error];
NSLog(@data is :::%@,data);
NSMutableDictionary * jsonDict =(NSMutableDictionary *)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:& error];
NSLog(@jsonDict is:%@,jsonDict);
但它是空的。你可以告诉我我在哪里做错了。 解决方案
U需要密钥才能申请Google Places API。
请参阅 SPGooglePlacesAutocomplete 链接,该链接符合您的要求。
编辑:请参阅文档。另请参阅如何注册Google地方信息
I am new to iOS programming. My requirement is to set the google places autocomplete request to a UITextField
.
I wrote the code as below
NSString *urlPath = [NSString stringWithFormat:@"/maps/api/place/autocomplete/json?input=%@&types=geocode&language=en-EN&sensor=false",string];
NSURL *url = [[NSURL alloc]initWithScheme:@"http" host:@"maps.googleapis.com" path:urlPath];
NSLog(@"url is:::%@",url);
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
NSURLResponse *response ;
NSError *error;
NSData *data;
data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(@"data is:::%@",data);
NSMutableDictionary *jsonDict= (NSMutableDictionary*)[NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(@"jsonDict is:%@",jsonDict);
But it gives empty. Can you tell me where I made wrong.
解决方案
U will need key to request Google Places API. Refer SPGooglePlacesAutocomplete link which is according to your requirement.
EDIT : Refer Documentation.Also refer how to register for Google Places
这篇关于如何设置谷歌地点的自动完成请求到iOS中的UITextField的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文