【发布时间】:2016-12-06 14:13:48
【问题描述】:
所以我有这个需要使用谷歌地图的操作扩展。通常当您想在 iOS 应用中使用 Google 地图时,您需要在 AppDelegates didFinishLaunchingWithOptions 函数中添加密钥。
在应用程序扩展中,您没有 AppDelegate 文件来执行此操作,那么我应该把它放在哪里?
我试着把它放进去:
override func viewDidLoad() {
GMSServices.provideAPIKey("KEY")
GMSPlacesClient.provideAPIKey("KEY")
super.viewDidLoad()
}
我也尝试将它放在super.viewDidLoad() 之后,但这并没有任何区别。
当我确定我有一个有效的位置时,我会在地图中加载一个视图:
func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
self.currentCoordinate = Coordinate(longitude: locations[0].coordinate.longitude, latitude: locations[0].coordinate.latitude)
let mapCameraPosition:GMSCameraPosition = GMSCameraPosition.cameraWithLatitude(self.currentCoordinate.latitude, longitude: self.currentCoordinate.longitude, zoom: 12)
let mapFrame:CGRect = CGRect(x: 0, y: 0, width: mapView.frame.width, height: 200)
let map:GMSMapView = GMSMapView.mapWithFrame(mapFrame, camera: mapCameraPosition)
self.mapView.addSubview(map)
}
我得到的视图看起来像like this:
在 Google 控制台中,我为主应用程序和扩展程序添加了捆绑标识符,并将这些标识符的使用限制为 ID。我已经重新生成了 API 密钥并再次添加了它。
我可以验证GoogleService-Info.plist 在应用运行时具有正确的 API 密钥...
我做错了什么?
更新
我已验证 'GMSServices.provideAPIKey("KEY")' 和 'GMSPlacesClient.provideAPIKey("KEY")' 均返回 true。因此得出结论,这不是 API 密钥问题。根据这个issue posted on code.google.com
,这似乎是一个已知问题【问题讨论】:
-
您是否在代码中添加了您的谷歌“KEY”?
-
不,那只是代表我正在使用的密钥。关键不重要。当然,在代码中我使用的是真正的密钥。
-
为谷歌地图启用详细并再次检查。
-
@New16 你能说得更具体点吗?我不确定我明白你的意思。
-
@Simonk 我对此感到困惑。检查 XCode 设备日志以检查错误。
标签: ios swift google-maps ios-extensions