这是我的代码:
let camera = GMSCameraPosition.camera(withLatitude: 51.5, longitude: -0.127, zoom: 12.0)
var mainView:UIView = GMSMapView.init(frame: CGRect(x:50,y:150,width:250,height:300))
self.view.addSubview(mainView)
let mapView = GMSMapView.map(withFrame: mainView.frame, camera: camera)
mainView = mapView
//Marker Position
let position = CLLocationCoordinate2D(latitude: 51.5, longitude: -0.127)
let london = GMSMarker(position: position)
london.title = "London"
london.icon = UIImage(named: "house")
london.map = mapView
答案 0 :(得分:0)
替换
var mainView:UIView = GMSMapView.init(frame: CGRect(x:50,y:150,width:250,height:300))
self.view.addSubview(mainView)
let mapView = GMSMapView.map(withFrame: mainView.frame, camera: camera)
mainView = mapView
使用
var mainView:GMSMapView! // instance var
// in viewDidLoad
let camera = GMSCameraPosition.camera(withLatitude: 51.5, longitude: -0.127, zoom: 12.0)
mainView = GMSMapView.map(withFrame:CGRect(x:50,y:150,width:250,height:300), camera: camera)
mapView.delegate = self
self.view.addSubview(mainView)