iOS Google Map API错误

问题描述 投票:1回答:1

嗨,当我在ios上使用谷歌地图时,我有一些问题。首先,我安装了可可豆荚并设置了google api。 (并将api密钥插入AppDelegate.swift文件中)

但是这个错误发生了:( - >线程1:信号SIGABRT

问题是什么

这是代码

import UIKit
import GoogleMaps

class LocationAddVC: UIViewController{

//Take a Google Map Object.
// Don't make outlet from Storyboard,
// Break the outlet of GMSMapView if you made an outlet

var mapView:GMSMapView?

override func viewDidLoad() {

    super.viewDidLoad()

    mapView = GMSMapView.map(withFrame: CGRect(x: 100, y: 100, width: 200, height: 200), camera: GMSCameraPosition.camera(withLatitude: 51.050657, longitude: 10.649514, zoom: 5.5))

    //so the mapView is of width 200, height 200 and its center is same as center of the self.view
    mapView?.center = self.view.center

    self.view.addSubview(mapView!)

 }

}
ios google-maps
1个回答
0
投票

我尝试了你的代码,它完美无缺。我删除了api-key或使用了错误键,发生了同样的错误。

我想你必须检查一些事情:

  1. 检查api-key是否在正确的位置初始化。 (参考我的代码)
  2. 检查api-key是否正确。
  3. 检查您是否在Google开发者帐户中启用了Map SDK for iOS应用。
  4. 最后,检查api-key的iOS包标识符没有限制。

这是我的工作代码:

AppDelegate中:

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {

    GMSServices.provideAPIKey("api-key")

    // Override point for customization after application launch.
    return true
}

视图控制器:

import UIKit
import GoogleMaps

class ViewController: UIViewController {

    var mapView:GMSMapView?

    override func viewDidLoad() {
        super.viewDidLoad()
        //Take a Google Map Object.
        // Don't make outlet from Storyboard,
        // Break the outlet of GMSMapView if you made an outlet

            mapView = GMSMapView.map(withFrame: CGRect(x: 100, y: 100, width: 200, height: 200), camera: GMSCameraPosition.camera(withLatitude: 51.050657, longitude: 10.649514, zoom: 5.5))

            //so the mapView is of width 200, height 200 and its center is same as center of the self.view
            mapView?.center = self.view.center

            self.view.addSubview(mapView!)

        }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
© www.soinside.com 2019 - 2024. All rights reserved.