嗨,当我在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或使用了错误键,发生了同样的错误。
我想你必须检查一些事情:
这是我的工作代码:
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.
}
}