Last active
September 7, 2020 22:26
-
-
Save DejanEnspyra/033ff58859c21fc8258c7684798f35d3 to your computer and use it in GitHub Desktop.
Set up custom Info Window in Google Maps iOS SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
extension ViewController: GMSMapViewDelegate{ | |
/* handles Info Window tap */ | |
func mapView(_ mapView: GMSMapView, didTapInfoWindowOf marker: GMSMarker) { | |
print("didTapInfoWindowOf") | |
} | |
/* handles Info Window long press */ | |
func mapView(_ mapView: GMSMapView, didLongPressInfoWindowOf marker: GMSMarker) { | |
print("didLongPressInfoWindowOf") | |
} | |
/* set a custom Info Window */ | |
func mapView(_ mapView: GMSMapView, markerInfoWindow marker: GMSMarker) -> UIView? { | |
let view = UIView(frame: CGRect.init(x: 0, y: 0, width: 200, height: 70)) | |
view.backgroundColor = UIColor.white | |
view.layer.cornerRadius = 6 | |
let lbl1 = UILabel(frame: CGRect.init(x: 8, y: 8, width: view.frame.size.width - 16, height: 15)) | |
lbl1.text = "Hi there!" | |
view.addSubview(lbl1) | |
let lbl2 = UILabel(frame: CGRect.init(x: lbl1.frame.origin.x, y: lbl1.frame.origin.y + lbl1.frame.size.height + 3, width: view.frame.size.width - 16, height: 15)) | |
lbl2.text = "I am a custom info window." | |
lbl2.font = UIFont.systemFont(ofSize: 14, weight: .light) | |
view.addSubview(lbl2) | |
return view | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYR, If we have implemented
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {}
then should
return false
from it.