Ivan Ivan - 1 month ago 35
iOS Question

Custom InfoWindow for marker Google Maps SDK, Swift 2.0

I'm trying to implement this (https://www.youtube.com/watch?v=ILiBXYscsyY) Custom InfoWindow tutorial that was done for Objective-C in Swift 2.0. I have tried doing this by just mix-matching Objective-C and Swift code, but I have been unsuccessful in translating

- (UIView *) mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker {
CustomInfoWindow *infoWindow = [[[NSBundle MainBundle] loadNibNamed:@"InfoWindow" owner:self options:nil] objectAtIndex:0];
infoWindow.name.text = @"Syndey Opera House";
infoWindow.address.text = @"Bennelong Point, Sydney";
infoWindow.photo.image = [UIImage imageNamed:@"SydneyOperaHouseAtNight"];

return infoWindow;
}


into Swift. This part of the tutorial can be found at 3:07 of the video.

I'd like some help in translating this tutorial into Swift 2.0 or if anyone knows of a good tutorial of this for Swift 2.0 that would be much appreciated.

Answer

Here is the swift code for the above:

func mapView(mapView: GMSMapView!, markerInfoWindow marker: GMSMarker!) -> UIView! {
         let infoWindow = NSBundle.mainBundle().loadNibNamed("InfoWindow", owner: self, options: nil).first as! CustomInfoWindow
        infoWindow.name.text = "Sydney Opera House"
        infoWindow.address.text = "Bennelong Point Sydney"
        infoWindow.photo.image = UIImage(named: "SydneyOperaHouseAtNight")
        return infoWindow
    }