lif*_*ott 0 debugging google-maps ios google-places-api swift
我一直在使用谷歌地图sdk和地方api完全正常.昨天我的代码运行得很好.但今天早上醒来,做了一些修改,然后遇到了一个问题的编译雪球,似乎很容易解决,但花了几个小时试图弄清楚发生了什么.我正在尝试开发一个iPhone应用程序.
我已经回去了,在开发者控制台中创建了一个"新项目",重新生成了一个新的iOS密钥.在info.plist中输入新的包ID,在委托文件中输入新的api密钥,并在url的搜索参数内输入.
我正在使用alamofire和swiftyjson来解析数据
但仍然得到同样的问题.
2016-01-28 13:15:55.683适用于iOS版的Google Maps SDK:1.11.21919.0
{"error_message":"此IP,站点或移动应用程序无权使用此API密钥.从IP地址"myIPAddress"收到请求,空引用","结果":[
],"status":"REQUEST_DENIED","html_attributions":[
]}
func downloadRestaurantDetails(completed: DownloadComplete) {
let URL_Search = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?"
let API_iOSKey = "My iOS API Key"
let urlString = "\(URL_Search)location=\(clLatitude),\(clLongitude)&radius=\(searchRadius)&types=\(searchType)&key=\(API_iOSKey)"
let url = NSURL(string: urlString)!
Alamofire.request(.GET,url).responseJSON { (response) -> Void in
if let value = response.result.value {
let json = JSON(value)
print(json)
if let results = json["results"].array {
for result in results {
if let placeIDs = result["place_id"].string {
self.placeIDArray.append(placeIDs)
}
}
}
}
completed()
}
}
Run Code Online (Sandbox Code Playgroud)
您的API密钥配置错误.
首先,您的问题在于Google Places API Web服务,该服务只能用于服务器密钥而不能用于iOS密钥.您正在调用Web服务(https://maps.googleapis.com/maps/place/...
),因此iOS密钥和bundleID密钥限制在这里不起作用(并且可能会混淆事物).
因此,您需要按照https://developers.google.com/places/web-service/get-api-key上的说明操作,并在开发者控制台中启用"Google Places API Web服务"的服务器密钥(不是与"Google Places API for iOS"相同.要在手机上有用,您可能不希望设置任何IP限制(并且IP限制是唯一可用于服务器密钥的类型).在HTTP请求中使用该密钥.
其他任何东西都会得到REQUEST_DENIED错误.
归档时间: |
|
查看次数: |
902 次 |
最近记录: |