[iOS] AIRGoogleMap didTapPolygon: crashes with an unrecognized-selector exception on a non-AIRGMSPolygon overlay tap

Author: ThomasPonzoVismaCreated Jun 8, 2026Updated Sep 7, 2026
Labelsstale

Summary

-[AIRGoogleMap didTapPolygon:] unconditionally casts the tapped overlay to AIRGMSPolygon. If any other GMSOverlay subclass reaches this handler, the app crashes with an unrecognized selector exception (e.g. -[GMSPolygon onPress]).

Environment

  • react-native-maps: 1.27.2
  • Platform: iOS, provider="google"
  • (Not specific to the New Architecture.)

Root cause

ios/AirGoogleMaps/AIRGoogleMap.mm:

objc
- (void)didTapPolygon:(GMSOverlay *)polygon {
    AIRGMSPolygon *airPolygon = (AIRGMSPolygon *)polygon;   // unchecked cast
    // ... accesses airPolygon.onPress / identifier ...
}

Any tapped overlay that is not an AIRGMSPolygon (a plain GMSPolygon, or another overlay type) hits the cast and crashes when the AIR-specific selectors are invoked.

Suggested fix

Guard the type before casting:

objc
- (void)didTapPolygon:(GMSOverlay *)polygon {
    if (![polygon isKindOfClass:[AIRGMSPolygon class]]) {
        return;
    }
    AIRGMSPolygon *airPolygon = (AIRGMSPolygon *)polygon;
    // ... unchanged ...
}

One-line guard; a working patch-package patch for 1.27.2 is available.

Source: react-native-maps/react-native-maps