Swift:我的 Google 地图视图未显示
Swift: My Google Maps View isn't showing up
我第一次尝试将 Google Maps SDK 实施到我的 iOS 应用程序中。按照 Google 的教程进行操作后,Google 地图仍然没有出现在我的视图中。
这是我的 AppDelegate 代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
GMSServices.provideAPIKey("\(myAPIKey)")
return true
}
这是我的视图控制器中的代码,直接来自 Google:
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapsView = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
但是,视图仍然没有显示。我检查了我的 IBOutlet 的视图 - mapsView - 它是正确的。这是我的故事板的图片:
空白视图是我的地图视图。但这里是我的应用程序运行时的样子:
将视图的自定义 class 更改为 Storyboard 中的 GMSMapView 而不是 UIView。
我第一次尝试将 Google Maps SDK 实施到我的 iOS 应用程序中。按照 Google 的教程进行操作后,Google 地图仍然没有出现在我的视图中。
这是我的 AppDelegate 代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
// Override point for customization after application launch.
GMSServices.provideAPIKey("\(myAPIKey)")
return true
}
这是我的视图控制器中的代码,直接来自 Google:
var camera = GMSCameraPosition.cameraWithLatitude(-33.86,
longitude: 151.20, zoom: 6)
var mapView = GMSMapView.mapWithFrame(CGRectZero, camera: camera)
mapView.myLocationEnabled = true
mapsView = mapView
var marker = GMSMarker()
marker.position = CLLocationCoordinate2DMake(-33.86, 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
但是,视图仍然没有显示。我检查了我的 IBOutlet 的视图 - mapsView - 它是正确的。这是我的故事板的图片:
空白视图是我的地图视图。但这里是我的应用程序运行时的样子:
将视图的自定义 class 更改为 Storyboard 中的 GMSMapView 而不是 UIView。