Reputation: 1255
I have a view containing a few google maps functions but for some odd reason the the "info window tapped " and "marker did tapped" doesn't do anything. Im not sure what Im missing. I have other extenstions in a few different files but i don't think that should cause any issues.
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
}
}
Upvotes: 2
Views: 3117
Reputation: 4448
For swift: import UIKit import GoogleMaps
class DemoViewController: UIViewController,
GMSMapViewDelegate {
}
When the GMSMapView is created, you can set its delegate to your view controller. The GMSMapViewDelegate provides only optional methods. To listen to any particular event, you must implement the relevant method.
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
}
// MARK: GMSMapViewDelegate
func mapView(_ mapView: GMSMapView, didTapAt coordinate: CLLocationCoordinate2D) {
print("You tapped at \(coordinate.latitude), \(coordinate.longitude)")
}
Upvotes: 0