【发布时间】:2017-05-31 11:04:36
【问题描述】:
我目前停留在此功能上,用户需要根据距离得出附近地点的结果。
例如:- 如果我搜索“高知”并且我在印度 然后高知在印度和日本 所以结果应该像 1. 印度高知 2. 日本高知
这只是一个例子,用户还可以搜索地标、城市、街道等。但我希望所有结果都按距离排序。更近的结果将首先显示,然后是远的地方。但无法按要求得到结果。
类似的功能是在 android 上完成的,他们通过半径来使用它(比如距离当前位置 500 公里)
到目前为止我所尝试的:-
- 使用 GMSPlacesClient.autocompleteQuery 并在其中传递当前位置的边界
GMSPlacesClient().autocompleteQuery(txtLocation.text!, bounds: bounds, filter: filter, callback: {(results, error) -> Void in
if let error = error {
print("Autocomplete error \(error)")
return
}
if let results = results {
}
})
- 使用 GooglePlaces.placeAutocomplete
GooglePlaces.placeAutocomplete(forInput: self.txtLocation.text!, offset: 0, locationCoordinate: nil, radius: nil, language: nil, types: [GooglePlaces.PlaceType.Regions], components: nil, completion: { (response, error) in
// To do
})
- 我也将这个 url (https://maps.googleapis.com/maps/api/place/autocomplete/json?input=pan&location=30.704316,76.712106&radius=50000&components=country:IN) 用于 Google API,但对于这些替代方案,我必须进行自定义解析。
【问题讨论】:
标签: ios swift google-maps google-places-api