我有一个包含一些谷歌地图功能的视图,但由于一些奇怪的原因,“信息窗口轻敲”和“标记确实点击”没有做任何事情。我不知道我错过了什么。我在几个不同的文件中有其他扩展,但我不认为这会引起任何问题。
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
}
}
答案 0 :(得分:0)
尝试在mapView.delegate = self
方法
viewDidLoad()
答案 1 :(得分:0)
要迅速: 导入UIKit 导入GoogleMaps
class DemoViewController: UIViewController,
GMSMapViewDelegate {
}
创建GMSMapView后,可以将其委托设置为视图控制器。 GMSMapViewDelegate仅提供可选方法。要收听任何特定事件,必须实现相关方法。
override func loadView() {
let camera = GMSCameraPosition.camera(withLatitude: 1.285,
longitude: 103.848,
zoom: 12)
let mapView = GMSMapView.map(withFrame: .zero, camera: camera)
mapView.delegate = self
self.view = mapView
}
//标记:GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
}