这已经在我的应用程序中起作用了很长时间,直到最近才停止工作。
func reverseGeocodeCoordinate(coordinate: CLLocationCoordinate2D, onSuccess : @escaping LocationUpdateSuccess) {
let geocoder = GMSGeocoder()
geocoder.reverseGeocodeCoordinate(coordinate) { response, error in
if let address = response?.firstResult() {
if let lines = address.lines! as? [String] {
let title = lines.joined(separator: " ")
if (title.characters.count) > 3 {
print(title)
onSuccess(coordinate, title)
}
}
}
else
{
print("Error In Reverse GeoCoding \n \(error?.localizedDescription)")
}
}
}
对于它的价值,这是我作为参数值发送的信息
CLLocationCoordinate2D
- latitude : 31.51774603759463
- longitude : 74.340778893683378
这是我发出请求时错误的确切文本
The operation couldn’t be completed. (com.google.HTTPStatus error 400.)
类似地
GMSPlacesClient().autocompleteQuery
将不响应以下函数中的结果
func autoCompleteQuery(searchText: String) {
if searchText.characters.count != 0 {
self.tableView.alpha = 1
let countryFilter = GMSAutocompleteFilter()
countryFilter.country = "US"
var areaBounds : GMSCoordinateBounds? = nil
if let lastSavedLocation = MyLocationManager.sharedInstance.lastSavedLocation
{
let lat = lastSavedLocation.coordinate.latitude
let long = lastSavedLocation.coordinate.longitude
let offset = 200.0 / 1000.0;
let latMax = lat + offset;
let latMin = lat - offset;
let lngOffset = offset * cos(lat * M_PI / 200.0);
let lngMax = long + lngOffset;
let lngMin = long - lngOffset;
let initialLocation = CLLocationCoordinate2D(latitude: latMax, longitude: lngMax)
let otherLocation = CLLocationCoordinate2D(latitude: latMin, longitude: lngMin)
areaBounds = GMSCoordinateBounds(coordinate: initialLocation, coordinate: otherLocation)
}
placesClient.autocompleteQuery(searchText, bounds: areaBounds, filter: countryFilter, callback: { (result, error) -> Void in
self.nearbyPlacesList.removeAll()
if result == nil {
print("Error in autocompleteQuery -> \(error?.localizedDescription)")
return
}
for result in result!{
if let result = result as? GMSAutocompletePrediction {
self.nearbyPlacesList.append((id: result.placeID!, name: result.attributedFullText.string))
self.tableView.reloadData()
}
}
})
} else {
self.tableView.alpha = 0
}
}
,并显示以下错误消息。
The operation couldn’t be completed. An internal error occurred in the Places API library. If you believe this error represents a bug, please file a report using the instructions on our community and support page (https://developers.google.com/places/ios-api/support).
我已经研究了答案here,重新安装了豆荚,什么也没有。
我还匹配了分发包标识符,取消了对API配额的限制,禁用并再次从Google的云控制台中启用了SDK,如下所示
但没有任何效果。任何帮助将不胜感激。谢谢
答案 0 :(得分:0)
对于以后某时来到此帖子的任何人来说,使用右键初始化GMS服务和地方都是问题。
GMSServices.provideAPIKey(<API_KEY_GOES_HERE>)
GMSPlacesClient.provideAPIKey(<API_KEY_GOES_HERE>)
我使用的项目中的旧密钥在Google Cloud Console上不再处于活动状态,因此返回了400错误。希望这对某人有帮助;)