这是我的代码:

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

最佳答案

更换

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)

关于ios - 为什么标记未显示在GMSMapView中?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/55337425/

10-12 04:23