Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Assign action tap to google map marker, swift 2

I have a google map marker and i want that when i tap the marker send me to another viewController, or display a button on my map,

let marker1 = GMSMarker()
marker1.position = CLLocationCoordinate2DMake(24.8236423, -107.4234671)
marker1.appearAnimation = kGMSMarkerAnimationPop
marker1.icon = UIImage(named: "flag_icon")
marker1.title = "Any title"
marker1.snippet = "Any text"
marker1.map = mapView
like image 931
altexo Avatar asked Jan 28 '26 14:01

altexo


1 Answers

I solved it, this is the tap function

    //Market Tap Function
func mapView(mapView: GMSMapView!, didTapMarker marker: GMSMarker!) -> Bool {
    let myFirstButton = UIButton()
    myFirstButton.setTitle("✸", forState: .Normal)
    myFirstButton.setTitleColor(UIColor.blueColor(), forState: .Normal)
    myFirstButton.frame = CGRectMake(15, -50, 300, 500)
    myFirstButton.addTarget(self, action: "pressed:", forControlEvents: .TouchUpInside)

    self.view.addSubview(myFirstButton)
    return true
}
like image 77
altexo Avatar answered Jan 31 '26 19:01

altexo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!