0

I have created a custom UIView with XIB and I display this when a user taps on a marker by implementing markerInfoWindow

- (UIView *)mapView:(GMSMapView *)mapView markerInfoWindow:(GMSMarker *)marker
{
    TESTInfoWindow *view =  [[[NSBundle mainBundle] loadNibNamed:@"TESTInfoWindow" owner:self options:nil] objectAtIndex:0];
    view.lblTitle.text = [marker title];
    return view;
}

Everything works fine, my XIB is displayed and the title populated.

My issue is that I can't get the custom UIView, TESTInfoWindow to respond to touch events. (I want the user to be able to drag the custom info window and the app will respond based on the touchesEnd event.)

I've implemented touchesBegan and touchesMoved in TESTInfoWindow and neither get called:

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    NSLog(@"DEBUG touchesBegan");  
}

-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        NSLog(@"DEBUG touchesMoved");  
}

I think the GMSMapView is receiving the touches that are ignored by the custom info window view.

How do I get my custom UIView to receive the touches? Any help appreciated.

Peter Todd
  • 8,561
  • 3
  • 32
  • 38

1 Answers1

0

I just copied the answer for you from this link 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
        NSNumber *number = [marker.userData objectForKey:@"marker_id"];
    }

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

Eg for set userData on GMSMarker object

GMSMarker *marker = [[GMSMarker alloc] init];
marker.userData = @{@"marker_id":[NSNumber numberWithInt:12]};
Community
  • 1
  • 1
Koti Tummala
  • 746
  • 6
  • 8