Google SDK中的didTapmarker不起作用



嗨,我在viewdidload中添加了纬度和经度的标记,当用户点击标记中的用户点击加载xib时,我想要在第一个我想要的xib中加载xib,当用户在标记中用户点击时,我想要的功能不起作用打印"胶带"!我的课:

class MapViewController: UIViewController {
    var ShopsInMap:[ObjectShop] = []
  var gmsMap = GMSMapView()
    override func viewDidLoad() {
        super.viewDidLoad()
        gmsMap.delegate = self
        setMarker()
    }
override func viewWillLayoutSubviews() {
    super.viewWillLayoutSubviews()
    self.gmsMap.frame = self.view.bounds
}

我使用此功能添加标记:

func setMarker(){
        let camera = GMSCameraPosition.camera(withLatitude:35.6892 , longitude: 51.3890, zoom: 10.0)
        let mapView = GMSMapView.map(withFrame: CGRect.zero, camera: camera)
        view = mapView
        for shopvalue in ShopsInMap{
            if (shopvalue.lat != ""){
                let marker = GMSMarker()
                print("lat : (Double(shopvalue.lat)!) lng is : (Double(shopvalue.lng)!)")
                marker.position = CLLocationCoordinate2D(latitude: Double(shopvalue.lat)!, longitude: Double(shopvalue.lng)!)
                marker.title = "(shopvalue.address) n (shopvalue.name)"
                marker.snippet = shopvalue.name
                marker.map = mapView
            }
        }
    }

我的扩展名是:

extension MapViewController :GMSMapViewDelegate{
    func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {
        print("marker tap : (marker.title)")
        return false
    }
    func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
        print("taped is : (coordinate.latitude)")
    }
    func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) {
    }
    func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
        let coustome = Bundle.main.loadNibNamed("CustomeWindowsInfo", owner: self, options: nil) as! CustomeWindowsInfo
        coustome.test.text = marker.title
        print("taped ifno : (marker.title)")
    }
}

我在堆栈溢出中阅读了所有问题,但是我可以使用此功能!感谢我的帮助

您需要在viewcontroller.view中添加地图并调整帧

class MapViewController: UIViewController {
    var ShopsInMap:[ObjectShop] = []
    var gmsMap = GMSMapView()
    override func viewDidLoad() {
        super.viewDidLoad()
        self.view.addSubView(gmsMap)
        gmsMap.delegate = self
        setMarker()
    }
override func viewDidLayoutSubviews() {
    super.viewDidLayoutSubviews()
    self.gmsMap.frame = self.view.bounds
}

func setMarker(){
        for shopvalue in ShopsInMap{
            if (shopvalue.lat != ""){
                let marker = GMSMarker()
                print("lat : (Double(shopvalue.lat)!) lng is : (Double(shopvalue.lng)!)")
                marker.position = CLLocationCoordinate2D(latitude: Double(shopvalue.lat)!, longitude: Double(shopvalue.lng)!)
                marker.title = "(shopvalue.address) n (shopvalue.name)"
                marker.snippet = shopvalue.name
                marker.map = self.gmsMap
            }
        }
    }

最新更新