Adding Click Event on Infowindow/Marker in Google Maps Sdk for Native iOS/Objective C

Adding Click Event on InfoWindow/Marker in Google Maps SDK for native iOS/objective C

1.conform to the GMSMapViewDelegate protocol.

@interface YourViewController () <GMSMapViewDelegate>
// your properties
@end

2.set your mapView_ delegate.

mapView_.delegate = self;

3.implement the GMSMapViewDelegate method

- (void)mapView:(GMSMapView *)mapView didTapInfoWindowOfMarker:(GMSMarker *)marker {
// your code
}

btw, marker.userData is useful. you can set your needed data into it and use it in - mapView:didTapInfoWindowOfMarker:

How can i add a button to google maps marker info window on ios?

The answer for the question you linked shows code for using MapKit, so it wouldn't work with the Google Maps SDK for iOS.

See this question for how to return a custom view with the Google Maps SDK for iOS:

Custom annotation view in Google Maps SDK

However note that according to this question, it looks like what is displayed might be a visual copy of the view not the actual view, which might limit the interaction you can do with the view:

Add buttons to view returned by markerInfoWindow delegate method

Simply detecting a tap on the info window and going to a different page should be possible using didTapWindowOfMarker though.

Note that there's a feature request in Google's issue tracker to add direct support for this:

https://code.google.com/p/gmaps-api-issues/issues/detail?id=4961

Select a marker method with Google Maps iOS SDK

I think you like this method

-(BOOL) mapView:(GMSMapView *) mapView didTapMarker:(GMSMarker *)marker
{
NSLog(@"try");
return YES;
}

Dont Forget to call delegate

@interface ViewController : UIViewController <GMSMapViewDelegate>

and

yourmapView_.delegate = self;

Custom InfoWindow for marker Google Maps SDK, Swift 2.0

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
}

Assign action tap to google map marker, swift 2

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
}


Related Topics



Leave a reply



Submit