【发布时间】:2018-06-09 11:32:54
【问题描述】:
我正在尝试获取附近的地点,但收到错误提供的 API 密钥无效。
//来自console.developers.google.com
我确实从控制台开发人员创建了项目,为 IOS 启用了 google places sdk,还生成了 API 密钥,并且从密钥限制中我选择了 IOS 应用程序并提供了我的密钥限制。
所以我的问题是我的代码有问题,或者需要做更多设置 console.developers.google.com
func getNearByPlace(place: String) {
var strGoogleApi = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?location=53.2734, -7.778320310000026&radius=50000&keyword=\(place)&sensor=true&key=\(googleApiKey) "
strGoogleApi = strGoogleApi.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)!
var urlRequest = URLRequest(url: URL(string: strGoogleApi)!)
urlRequest.httpMethod = "GET"
let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, error) in
if error == nil {
let jsonDict = try? JSONSerialization.jsonObject(with: data!, options: .mutableContainers)
print("Json == \(jsonDict!)")
} else {
}
}
task.resume()
}
【问题讨论】:
标签: ios google-maps google-places-api swift4