Creating custom info window in swift with the Google maps iOS sdk?

10,090

You can implement the markerInfoWindow method from GMSMapViewDelegate

Sample implementation to show an custom info window in Swift:

 func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
        var infoWindow = NSBundle.mainBundle().loadNibNamed("CustomInfoWindow", owner: self, options: nil).first! as CustomInfoWindow
        infoWindow.label.text = "\(marker.position.latitude) \(marker.position.longitude)"
        return infoWindow
 }

You can visit this GitHub page for detail implementation.

Depends on how you want your info window looks like, you can change the background color by doing infoWindow.backgroundColor = UIColor.redColor(), or change the shape of your info window by doing infoWindow.layer.cornerRadius = 10.0f, or even add an image by doing infoWindow.imageView.image = UIImage(named: "image.jpg").

Share:
10,090
user3280937
Author by

user3280937

Updated on June 06, 2022

Comments

  • user3280937
    user3280937 almost 2 years

    I have created a xib and a view controller, and want to display it a customised info window for a marker in swift. After searching on the Internet I have found an old tutorial in OBJ-C however this will not help me.

    Thank you.

  • user3280937
    user3280937 about 9 years
    Is there anyway of making this look more like an info window instead of just a square box.
  • ztan
    ztan about 9 years
    Please see my edited answer @user3280937, it really depends on how you want your info window looks like, you can do a lot of customization in your xib file or do in code.