我有一个包含一些谷歌地图功能的视图,但是由于一些奇怪的原因,“信息窗口被点击”和“标记被点击”没有任何作用。我不知道我错过了什么。我在一些不同的文件中有其他扩展名,但我认为这不会引起任何问题。

import UIKit
import Firebase
import FirebaseDatabase
import FirebaseAuth
import CoreLocation
import GoogleMaps
import Font_Awesome_Swift


class DasboardVC: UIViewController, CLLocationManagerDelegate, GMSMapViewDelegate {

    //UnwindSegue
    @IBAction func unwindSegueDashboard(segue:UIStoryboardSegue){}

    //var sidebar items

    @IBOutlet weak var mapView: GMSMapView!
    @IBOutlet weak var addPhotoLabel: UILabel!
    @IBOutlet weak var showSideBar: UIButton!
    @IBOutlet weak var hideMenuIcon: UIButton!
    @IBOutlet weak var profileImage: UIImageView!
    @IBOutlet weak var editProfileButon: UIButton!
    @IBOutlet weak var message: UIButton!
    @IBOutlet weak var settings: UIButton!
    @IBOutlet weak var logout: UIButton!
    @IBOutlet weak var sidebarView: UIView!
    @IBOutlet weak var activityButton: UIButton!
    @IBOutlet weak var jobRequestSwitch: UISwitch!
    @IBOutlet weak var topBar: UIView!
    @IBOutlet weak var removePhoto: UIButton!


    let profileImageController = ProfileImageVC()
    let photoController = ProfilePicClass()


    //MapView Vars
    var locationManager = CLLocationManager()
    var didFindMyLocation = false
    var locationMarker: GMSMarker!


    override func viewWillAppear(animated: Bool) {

        sidebarView.hidden = true
        removePhoto.hidden = true
        topBar.backgroundColor = main()
        hideNavBar()
        sideBarMenuButton()

       // sidebarProfileImage()
       photoController.profileImage(profileImage, noImageLabel: addPhotoLabel)

    }
    override func viewWillDisappear(animated: Bool) {
        showNavBar()
        viewloadedMap()

    }

    override func viewDidLoad() {

        mapInset()

        mapView.addObserver(self, forKeyPath: "myLocation", options: NSKeyValueObservingOptions.New, context: nil)

        mapView.myLocationEnabled = true
        mapView.settings.myLocationButton = true


        let ihelprCoordinate:CLLocationCoordinate2D = CLLocationCoordinate2DMake(37.332052, -122.031088)


            ihelprLocation(ihelprCoordinate)


    }

    func mapView(mapView: GMSMapView, didTapInfoWindowOfMarker marker: GMSMarker) {
        print("infoWindowTapped")
    }

    func mapView(mapView: GMSMapView, didTapMarker marker: GMSMarker) -> Bool {
        print("markerTapped")

        return true
    }



}

最佳答案

尝试在mapView.delegate = self方法中添加viewDidLoad()

关于swift - swift 的Google map 代表无法正常工作,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/37505900/

10-12 14:35