Ios 谷歌地图SDK(GMSMapView)与Swift崩溃
我添加了带有pods的GoogleMap SDK,它位于Ios 谷歌地图SDK(GMSMapView)与Swift崩溃,ios,swift,google-maps,Ios,Swift,Google Maps,我添加了带有pods的GoogleMap SDK,它位于Objective-C中 我在Swift项目中使用桥头 在appdelegate中,我使用此代码提供api密钥 GoogleMapsService.provideAPIKey(kGooglePlacesApiKey) // where kGooglePlacesApiKey is the key generated on google console. 在ViewController中,我使用下面的代码添加Google地图 func ad
Objective-C
中
我在Swift
项目中使用桥头
在appdelegate中,我使用此代码提供api密钥
GoogleMapsService.provideAPIKey(kGooglePlacesApiKey)
// where kGooglePlacesApiKey is the key generated on google console.
在ViewController中,我使用下面的代码添加Google地图
func addGoogleMap()
{
let camera = GMSCameraPosition.cameraWithLatitude(51.5074,
longitude: 0.1278, zoom: 10)
mapView = GMSMapView.mapWithFrame(CGRectMake(0, 157, self.view.frame.size.width, self.view.frame.size.height - 206.1), camera:
camera)
mapView.myLocationEnabled = true
mapView.delegate = self
self.view .addSubview(mapView)
}
当我尝试创建GMSMapView的对象时,它总是在这一行崩溃:
mapView = GMSMapView.mapWithFrame(CGRectMake(0, 157, self.view.frame.size.width, self.view.frame.size.height - 206.1), camera:
camera)
它没有给出任何错误日志,只是切换到appdelegate并以红色显示错误
创建一个CGRect,将所需的框架设置为mapview框架
var gframe = CGRectMake(0, 157, self.view.frame.size.width, self.view.frame.size.height - 206.1)
mapView = GMSMapView.mapWithFrame(gframe, camera:camera)
创建一个CGRect,将所需的框架设置为mapview框架
var gframe = CGRectMake(0, 157, self.view.frame.size.width, self.view.frame.size.height - 206.1)
mapView = GMSMapView.mapWithFrame(gframe, camera:camera)