0

I want to add a custom info window to pop up in Google Maps whenever someone taps a pin. I've already hidden the current info window by not passing it any data and know that the function

func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {

    return true
}

Handles what happens when a pin is tapped. I currently have this custom UIView and attributes on my MapViewController and the corresponding outlets added to the ViewController code: enter image description here

How would I implement this UIView to pop up whenever I tap a pin?

ch1maera
  • 1,369
  • 5
  • 20
  • 42
  • try this https://stackoverflow.com/questions/29462187/creating-custom-info-window-in-swift-with-the-google-maps-ios-sdk – Harsh Sharma May 01 '17 at 04:10
  • https://medium.com/@matschmidy/how-to-implement-custom-and-dynamic-map-marker-info-windows-for-google-maps-ios-e9d993ef46d4 – Anurag Sharma Jul 08 '20 at 12:03

2 Answers2

2

You should create a custom view for the annotation and then return that custom view for the following method:

func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
 //Create and load your custom view here and then return the view
}
Zach Fuller
  • 1,219
  • 2
  • 14
  • 18
2

you have to use GMSMapViewDelegate to use markerInfoWindow to your class.

let mapview = GMSMapView.map(withFrame: CGRect.zero, camera: camera)

mapview.delegate = self


func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? {
    // Get a reference for the custom overlay
    let index:Int! = Int(marker.accessibilityLabel!)
    let customInfoWindow = Bundle.main.loadNibNamed("CustomInfoWindow", owner: self, options: nil)?[0] as! CustomInfoWindow
    customInfoWindow.Timings.text = States[index].time
    customInfoWindow.Title.text = States[index].name
    customInfoWindow.Direction_Button.tag = index
    customInfoWindow.Direction_Button.addTarget(self, action: #selector(GetDirectionsAction(sender:)), for: .touchUpInside)

    return customInfoWindow
}
dhanasekar
  • 1,228
  • 13
  • 16