I am getting Use of undeclared identifier 'AIRGoogleMapOverlay'
error when I am trying to run my react native project through Xcode. I am actually trying to open the app on my iPhone and thats when I encounter this error. If I simply say react-native run-ios, it builds and launches the app on simulator. I am trying to extract current device location which I can't do using a simulator.
The error occurs in the AirGoogleMapOverlayManager.m file which exists in the react-native-google-maps package.
AIRGoogleMapOverlay.h
#ifdef HAVE_GOOGLE_MAPS
#import <Foundation/Foundation.h>
#import <GoogleMaps/GoogleMaps.h>
#import <React/RCTBridge.h>
#import "AIRMapCoordinate.h"
#import "AIRGoogleMap.h"
@interface AIRGoogleMapOverlay : UIView
@property (nonatomic, strong) GMSGroundOverlay *overlay;
@property (nonatomic, copy) NSString *imageSrc;
@property (nonatomic, strong, readonly) UIImage *overlayImage;
@property (nonatomic, copy) NSArray *boundsRect;
@property (nonatomic, readonly) GMSCoordinateBounds *overlayBounds;
@property (nonatomic, weak) RCTBridge *bridge;
@end
#endif
AIRGoogleMapOverlay.m
#ifdef HAVE_GOOGLE_MAPS
#import "AIRGoogleMapOverlay.h"
#import <React/RCTEventDispatcher.h>
#import <React/RCTImageLoader.h>
#import <React/RCTUtils.h>
#import <React/UIView+React.h>
@interface AIRGoogleMapOverlay()
@property (nonatomic, strong, readwrite) UIImage *overlayImage;
@property (nonatomic, readwrite) GMSCoordinateBounds *overlayBounds;
@end
@implementation AIRGoogleMapOverlay {
RCTImageLoaderCancellationBlock _reloadImageCancellationBlock;
CLLocationCoordinate2D _southWest;
CLLocationCoordinate2D _northEast;
}
- (instancetype)init
{
if ((self = [super init])) {
_overlay = [[GMSGroundOverlay alloc] init];
}
return self;
}
- (void)setImageSrc:(NSString *)imageSrc
{
NSLog(@">>> SET IMAGESRC: %@", imageSrc);
_imageSrc = imageSrc;
if (_reloadImageCancellationBlock) {
_reloadImageCancellationBlock();
_reloadImageCancellationBlock = nil;
}
__weak typeof(self) weakSelf = self;
_reloadImageCancellationBlock = [_bridge.imageLoader loadImageWithURLRequest:[RCTConvert NSURLRequest:_imageSrc]
size:weakSelf.bounds.size
scale:RCTScreenScale()
clipped:YES
resizeMode:RCTResizeModeCenter
progressBlock:nil
partialLoadBlock:nil
completionBlock:^(NSError *error, UIImage *image) {
if (error) {
NSLog(@"%@", error);
}
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(@">>> IMAGE: %@", image);
weakSelf.overlayImage = image;
weakSelf.overlay.icon = image;
});
}];
}
- (void)setBoundsRect:(NSArray *)boundsRect
{
_boundsRect = boundsRect;
_southWest = CLLocationCoordinate2DMake([boundsRect[1][0] doubleValue], [boundsRect[0][1] doubleValue]);
_northEast = CLLocationCoordinate2DMake([boundsRect[0][0] doubleValue], [boundsRect[1][1] doubleValue]);
_overlayBounds = [[GMSCoordinateBounds alloc] initWithCoordinate:_southWest
coordinate:_northEast];
_overlay.bounds = _overlayBounds;
}
@end
#endif
And here is where I get the error, in AIRGoogleMapOverlayManager
#import "AIRGoogleMapOverlayManager.h"
#import "AIRGoogleMapOverlay.h"
@interface AIRGoogleMapOverlayManager()
@end
@implementation AIRGoogleMapOverlayManager
- (UIView *)view
{
AIRGoogleMapOverlay *overlay = [AIRGoogleMapOverlay new]; ERROR-Use of undeclared identifier 'AIRGoogleMApOverlay'
overlay.bridge = self.bridge; ERROR-Use of undeclared identifier 'overlay'
return overlay; ERROR-Use of undeclared identifier 'overlay'
return 0;
}
RCT_EXPORT_MODULE()
RCT_REMAP_VIEW_PROPERTY(bounds, boundsRect, NSArray)
RCT_REMAP_VIEW_PROPERTY(image, imageSrc, NSString)
@end
I know that solving the first will get rid of all 3 errors. Also I am running xcworkspace, not xcodeproj.
Any help is appreciated!
I added HAVE_GOOGLE_MAPS=1
to the preprocessor macros, all the AIRGoogleMapOverlay related errors were gone.
This needs to be added for both Debug and Release in case someone is wondering why they are getting this error while trying to create an offline bundle.