0

I want to have a custom info window in my application that will appear in place of the default one when I click on a Google Maps marker. To do this, I have created a .xib file and a CustomInfoWindow.swift class that looks like this:

import UIKit

class CustomInfoWindow: UIView {

    @IBOutlet var label: UIImageView!

}

However, I don't know how to get my map to show this info window when I click on the marker. I have looked here, here and here for help with no luck.

I have implemented the following code:

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

However, when I try to build this, I get an error saying that I "cannot call value of non-function type Bundle".

Community
  • 1
  • 1
rustbird
  • 155
  • 1
  • 5
  • Implement the GMSMapViewDelegate(markerInfoWindow marker:) method and return your view in that method. – Karthick Selvaraj Mar 29 '17 at 13:13
  • You should show us what you've already tried and how that failed. SO is not for asking others to write the code for you. Why did the articles you mention not help? There's quite a lot of information there to show how to do this. – dirkgroten Mar 29 '17 at 13:18
  • @dirkgroten I've tried this method: 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 } As given in one of the above tutorials, but I'm running into trouble with the NSBundle - I have to rewrite as Bundle, but then it says I cannot call the value of non-function type Bundle. – rustbird Mar 29 '17 at 13:23
  • can you update your question? This is impossible to read. – dirkgroten Mar 29 '17 at 13:25
  • "I have to rewrite as Bundle"??? What do you mean by that? `let mainBundle = Bundle.main` then `mainBundle.loadNibNamed...` should work – dirkgroten Mar 29 '17 at 13:29
  • @dirkgroten just edited. Thank you for being patient, I am genuinely confused. – rustbird Mar 29 '17 at 13:38
  • Look up the docs for [Bundle](https://developer.apple.com/reference/foundation/bundle). To get the main bundle it's `Bundle.main` not `Bundle.mainBundle()`. – dirkgroten Mar 29 '17 at 13:41

0 Answers0