【发布时间】:2018-05-16 10:22:52
【问题描述】:
我正在尝试从邮政编码获取坐标,但出现错误
{ "error_message" = "此 IP、站点或移动应用程序无权使用此 API 密钥。从 IP 地址收到请求 0.0.0.0.,引用者为空"; 结果 = ( ); status = "REQUEST_DENIED"; }
这是我的代码:
public func getLocationFromAddress(zipCode : String) -> CLLocationCoordinate2D {
let lat : Double = 0.0
let lon : Double = 0.0
let strUrl = "https://maps.googleapis.com/maps/api/geocode/json?address=\(zipCode)&key=\(Global.kGoogleApiKey.strPlaceAPIKey)&sensor=false"
let escapedString = strUrl.addingPercentEncoding(withAllowedCharacters: .urlQueryAllowed)
AFAPIMaster.sharedAPIMaster.getLatLongCallApi_Completion(strGetURL:escapedString!,params: nil, showLoader: true, enableInteraction: false, viewObj:self.view, onSuccess: { (result) in
if let Dict = result as? NSDictionary {
print(Dict)
}
}, onFailure: { })
return CLLocationCoordinate2D(latitude: lat, longitude: lon)
}
【问题讨论】:
-
您使用的 API 密钥不起作用
-
我必须创建服务器密钥?
标签: ios swift google-maps