我有一个GMSMapView
实例orderMapView
,该实例链接到我的UIViewController
。我授予了位置许可权,后来成为orderMapView
orderMapView.delegate = self
我也使该类符合GMSMapViewDelegate
。然后,我在viewDidLoad
中启动多个标记,其中之一是这样的:
let marker = GMSMarker()
marker.position = CLLocationCoordinate2D(latitude: CLLocationDegrees(dataLat), longitude: CLLocationDegrees(dataLng))
marker.title = dataName
marker.snippet = "LAT: \(dataLat), LONG: \(dataLng)"
marker.appearAnimation = .pop
marker.map = orderMapView
marker.isDraggable = true
marker.isTappable = true
我还实现了以下委托方法:
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D){
//1 - IT NEITHER COMES HERE
print(coordinate)
}
func mapView(_ mapView: GMSMapView, idleAt position: GMSCameraPosition) {
print(position)
}
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
//2 - IT NEITHER COMES HERE
orderMapView.selectedMarker = marker
return true
}
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 70))
view.backgroundColor = UIColor.white
view.layer.cornerRadius = 6
let lbl1 = UILabel(frame: CGRect.init(x: 8, y: 8, width: view.frame.size.width - 16, height: 15))
lbl1.text = marker.title
view.addSubview(lbl1)
let lbl2 = UILabel(frame: CGRect.init(x: lbl1.frame.origin.x, y: lbl1.frame.origin.y + lbl1.frame.size.height + 3, width: view.frame.size.width - 16, height: 15))
lbl2.text = marker.snippet
lbl2.font = UIFont.systemFont(ofSize: 14, weight: .light)
view.addSubview(lbl2)
return view
}
我可以在地图上看到标记,但是当我点击它时,地图会缩小,并且永远不会在这些标记上显示信息窗口。请帮忙。
更新:这是在模拟器上发生的,因为我没有设备。那会是唯一的酸痛问题吗?