我使用的是xcode 9.0,GoogleMaps SDK 2.5.0和GooglePlaces 2.5.0。
在func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool
方法中,我尝试禁用自动中心地图,当我选择标记并返回仅显示标记但未启用自动中心的旧行为时。问题是,当我实现该行为(被注释的行)时,标记不会出现,我搜索的所有堆栈溢出都会实现这些行。我迷失了
class MapViewController: UIViewController, GMSMapViewDelegate
{
//MARK: Class Life Cycle
@IBOutlet weak var mapView: UIView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
setupUI()
setupMap()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
//MARK: -Setup
func setupUI() {
navigationController?.hideBar()
}
func setupMap() {
let map = MapManager.sharedInstance.setupMap(view: mapView, latitude: GoogleMap.latitude, longitude: GoogleMap.longitude, zoom: GoogleMap.zoom)
map.delegate = self
mapView.addSubview(map)
MapManager.sharedInstance.setupMapMarkers(map: map, file: File.geoFence, fileType: File.json)
}
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
// mapView.selectedMarker = marker
// return true
return false
}
}
答案 0 :(得分:0)
如果有人遇到这个奇怪的错误,奇怪的解决方案是再次添加代表:
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
mapView.delegate = self
mapView.selectedMarker = marker
return true
return false
}