iBe*_*ner 8 google-maps ios google-maps-sdk-ios swift
我正在尝试使用Swift 2.0将Google Maps SDK实现到我的项目中.我遵循这个,但在运行时,我的应用程序收到以下错误:
2015-08-25 19:05:17.337 googleMap[1919:54102] *** Terminating app due to uncaught exception 'GMSServicesException', reason: 'Google Maps SDK for iOS must be initialized via [GMSServices provideAPIKey:...] prior to use
*** First throw call stack:
(
0 CoreFoundation 0x00000001058499b5 __exceptionPreprocess + 165
...
...
...
31 UIKit 0x000000010606699e UIApplicationMain + 171
32 googleMap 0x00000001034b720d main + 109
33 libdyld.dylib 0x0000000107fba92d start + 1
34 ??? 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException
Run Code Online (Sandbox Code Playgroud)
我已尝试过StackOverflow的所有可能解决方案.
小智 27
您需要在didFinishLaunchingWithOptions中设置它
GMSPlacesClient.provideAPIKey("Your key")
GMSServices.provideAPIKey("Your key")
Run Code Online (Sandbox Code Playgroud)
小智 16
我刚遇到同样的问题.我创建了一个GMSMapView对象,并且可能在读取api密钥之前对其进行了初始化.所以我在viewDidLoad方法中移动它并解决了问题.
之前:
class ViewController: ..... {
let mapView = GMSMapView()
Run Code Online (Sandbox Code Playgroud)
之后:
class ViewController: ..... {
var mapView : GMSMapView?
override viewDidLoad(){
mapView = GMSMapView()
Run Code Online (Sandbox Code Playgroud)
小智 13
刚加入Rajasekaran Gopal
记得加
import GoogleMaps
import GooglePlaces
Run Code Online (Sandbox Code Playgroud)
然后
GMSPlacesClient.provideAPIKey("Your key")
GMSServices.provideAPIKey("Your key")
Run Code Online (Sandbox Code Playgroud)
在didFinishLaunchingWithOptions中
这是 Swift 的 Google 地图教程:
http://www.appcoda.com/google-maps-api-tutorial/
以下引自谷歌地图文档:
第 5 步:获取 iOS API 密钥
使用 API 密钥可让您监控应用程序的 API 使用情况,并确保 Google 可以在必要时就您的应用程序与您联系。该密钥是免费的,您可以将其用于任何调用 iOS 版 Google Maps SDK 的应用程序,并且它支持无限数量的用户。您可以通过提供应用程序的包标识符从 Google Developers Console 获取 API 密钥。
如果您的项目还没有 iOS 应用程序的密钥,请按照以下步骤从 Google Developers Console 创建 API 密钥:
- 在左侧的边栏中,选择Credentials。
- 如果您的项目还没有 iOS API 密钥,请立即通过选择添加凭据 > API 密钥 > iOS 密钥来创建一个。
- 在出现的对话框中,输入您的应用程序包标识符。例如:
com.example.hellomap。单击创建。
您的新 iOS API 密钥出现在您项目的 API 密钥列表中。API 密钥是一串字符,如下所示:
AIzaSyBdVl-cTICSwYKrZ95SuvNw7dbMuDt1KG0将您的 API 密钥添加到您
AppDelegate.m的如下:
- 添加以下导入语句:
@import GoogleMaps;
- 将以下内容添加到您的应用程序:didFinishLaunchingWithOptions: 方法,将 API_KEY 替换为您的 API 密钥:
[GMSServices provideAPIKey:@"API_KEY"];