iOS Google Map API错误

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS Google Map API错误相关的知识,希望对你有一定的参考价值。

嗨,当我在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!)

 }

}
答案

我尝试了你的代码,它完美无缺。我删除了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.
    }
}

以上是关于iOS Google Map API错误的主要内容,如果未能解决你的问题,请参考以下文章

Google Map API - 移除标记

Google api 密钥不适用于我的 ios 应用程序

Google Map/Places API 是不是与 iOS 6 兼容?

如何使用 API 在 google map xamarin iOS 上更新 PIN 中的信息

android google map supportmap片段无法在片段中初始化

IOS : Cordova App Crash on Google Map api zoom in ios 11.3 iphone x