作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我想将 GMSMapView 添加到 currentView 作为 subview 但是它显示黑页这里是我的代码
let viewTest = UIView()
viewTest.frame = CGRect.init(x: 16, y: 50, width: 300, height: 100)
let camera = GMSCameraPosition.camera(withLatitude: -33.86, longitude: 151.20, zoom: 6.0)
let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
mapView.delegate = self
// Creates a marker in the center of the map.
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: -33.86, longitude: 151.20)
marker.title = "Sydney"
marker.snippet = "Australia"
marker.map = mapView
viewTest.addSubview(mapView)
如果我将 viewTest.addSubview(mapView)
更改为 self.view = mapView
它可以正常显示在我的整个 View 中的 map 。
如果我更改 viewTest = mapView
。我得到一个没有 map 显示的白屏,并出现以下错误。
" current[11927:300222] [BoringSSL] Function nw_protocol_boringssl_input_finished: line 1436 Peer disconnected during the middle of a handshake. Sending errSSLFatalAlert(-9802) alert 2018-06-23 00:56:12.499396-0400 current[11927:300222] TIC TCP Conn Failed [1:0x604000179c80]: 3:-9802 Err(-9802) "
最佳答案
您可以创建 View 的 IBOutlet
并将其类设置为 GMSMapView
。
为其创建属性。
@IBOutlet weak var view_mapContainer: GMSMapView!
最后你可以设置它的属性。
let coord = CLLocationCoordinate2D(latitude: 12.123312, longitude: 76.123123) //set lat long of the location you want to set
self.view_mapContainer.camera = GMSCameraPosition(target: coord, zoom: 13, bearing: 0, viewingAngle: 0)
let marker = GMSMarker()
marker.icon = UIImage(named: "ImageToSet")
marker.appearAnimation = GMSMarkerAnimation(rawValue: 1)!
marker.position = coord
marker.title = "any title"
marker.snippet = "any snippet"
marker.map = self.view_mapContainer
关于ios - 如何在 swift 4 中将 GMSMapView 添加到 View 的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50998070/
我是一名优秀的程序员,十分优秀!