【问题标题】:iOS8: Best way to autocomplete address searching?iOS8:自动完成地址搜索的最佳方式?
【发布时间】:2014-12-27 06:07:37
【问题描述】:

我有一个应用程序,允许用户在文本字段中输入地址。我想要一个关联的 tableView 填充他们正在寻找的地址的自动完成猜测(例如优步的方式)。到目前为止,我已经使用 MapKit 构建了我的应用程序 - 有没有办法使用 MapKit 来做到这一点,或者 Google Maps SDK 是要走的路吗?

【问题讨论】:

    标签: ios objective-c google-maps-api-3 mapkit


    【解决方案1】:

    SPGooglePlacesAutocomplete 是围绕 Google Places Autocomplete API 的简单 Objective-c 包装器。

    看看这个来自 github 的 API 可能会有所帮助-https://github.com/spoletto/SPGooglePlacesAutocomplete

    按链接显示的用法。添加 .h 文件,您可以从函数中访问实现 Google Place API 的函数。您可以设置参数,例如部分地址字符串、半径、您的应用使用的语言、您的位置(纬度、经度)

    #import "SPGooglePlacesAutocompleteQuery.h"
    
    ...
    
    SPGooglePlacesAutocompleteQuery *query = [SPGooglePlacesAutocompleteQuery query];
    query.input = @"185 berry str";
    query.radius = 100.0;
    query.language = @"en";
    query.types = SPPlaceTypeGeocode; // Only return geocoding (address) results.
    query.location = CLLocationCoordinate2DMake(37.76999, -122.44696)
    

    然后,调用 -fetchPlaces 来 ping Google 的 API 并获取结果。结果数组将返回 SPGooglePlacesAutocompletePlace 类的对象。

    [query fetchPlaces:^(NSArray *places, NSError *error) {
        NSLog(@"Places returned %@", places);
    }];
    

    它还有一个可以使用的示例项目。

    【讨论】:

    • 我无法使用它。我已经下载了这个 Objective-C 包装器。当我使用这些类时,会出现很多错误,例如找不到某些字符串,您能帮忙吗
    【解决方案2】:

    仅供参考,这违反了 Google 的条款和条件,您可以阅读更多相关信息 here

    他们已经明确提到了

    如果您的应用程序在 地图,该地图必须由 Google 提供。

    您也可以使用 Apple Map Kit 本身来实现这一点。

    您可以使用MKLocalSearchRequest

    可以从HERE下载示例项目。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-08-05
      • 1970-01-01
      • 2011-05-15
      • 2016-06-23
      • 1970-01-01
      • 1970-01-01
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多