使用谷歌API自动完成搜索栏?

时间:2013-12-16 12:42:02

标签: iphone autocomplete ios7 google-api xcode5

我是ios中的新手,我想使用谷歌API制作自动完成搜索栏...请告诉我如何才能使用谷歌API自动完成搜索栏..

我使用了以下网址,但如何使用搜索栏...

- (NSString *)description
{
return [NSString stringWithFormat:@"Query URL: %@", [self googleURLString]];
}


- (NSString *)googleURLString
{
   NSMutableString *url = [NSMutableString stringWithFormat:@"https://maps.googleapis.com/maps/api/place/autocomplete/json?input=%@&sensor=%@&key=%@",
                        [self.input stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding],
                        SPBooleanStringForBool(self.sensor), self.key];

if (self.offset != NSNotFound) {
    [url appendFormat:@"&offset=%u", self.offset];
}
if (self.location.latitude != -1) {
    [url appendFormat:@"&location=%f,%f", self.location.latitude, self.location.longitude];
    NSLog(@"%@",url);
}
if (self.radius != NSNotFound) {
    [url appendFormat:@"&radius=%f", self.radius];
}
if (self.language) {
    [url appendFormat:@"&language=%@", self.language];
}

return url;
}

1 个答案:

答案 0 :(得分:0)

查看https://github.com/spoletto/SPGooglePlacesAutocomplete

这是Google商家信息自动填充API的客观包装。

祝你好运!