Skip to content

Commit 5538eb3

Browse files
committed
Enable custom configuration for iOS maps
This allows setting up the library to work with Google Maps on iOS via `react-native link` instead of only via CocoaPods. Because Google-Maps-iOS-Utils is not distributed as a binary (at this time), it disables functionality that depends on this library and raises an exception that points to the reason why there's a problem. Additionally: - A missing file has been added back into the AirMaps.xcodeproj project.
1 parent c3b3802 commit 5538eb3

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+232
-21
lines changed

docs/installation.md

+28-15
Original file line numberDiff line numberDiff line change
@@ -80,20 +80,24 @@ post_install do |installer|
8080
end
8181
~~~
8282

83+
## iOS - ReactNative Link
8384

84-
## IMPORTANT!!
85+
Run `react-native link react-native-maps`. Note that by default this will use
86+
Apple Maps and that the configuration of Google Maps will be more difficult.
8587

86-
**!! DO NOT USE !!** `react-native link`
88+
Functionality that depends on `Google-Maps-iOS-Utils` has been disabled for this
89+
configuration via runtime errors due to the fact that this framework is not
90+
available for download as a pre-compiled binary. An exception will be raised if
91+
you try to use the following features:
8792

88-
Have ran it already? Read [this](#on-ios).
93+
- Making markers via KML files
8994

9095
## If you want to use Google maps
9196

92-
9397
Add to `ios/_YOUR_PROJECT_NAME_/AppDelegate.m:
9498

9599
```objc
96-
+ @import GoogleMaps; //add this line if you want to use Google Maps
100+
+ #import <GoogleMaps/GoogleMaps.h>
97101

98102
@implementation AppDelegate
99103
...
@@ -106,6 +110,25 @@ Add to `ios/_YOUR_PROJECT_NAME_/AppDelegate.m:
106110
107111
This should be the **first line** of the method.
108112
113+
#### If you are not using CocoaPods
114+
115+
If you installed via `react-native-link`, add the following to your
116+
`package.json` and replace the `REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL`
117+
with the relative path from your project root to the directory in which you
118+
installed the Google Maps frameworks:
119+
120+
```json
121+
{
122+
"name": "your-app",
123+
"scripts": {
124+
"postinstall": "./node_modules/react-native-maps/enable-google-maps REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL"
125+
}
126+
}
127+
```
128+
129+
Re-run `npm install` or `yarn` to ensure the `postinstall` script is run.
130+
131+
109132
## Notes on running on a real ios device
110133

111134
The steps are as described in https://facebook.github.io/react-native/docs/running-on-device.html , however instead of opening the .xcodeproj file you should open .xcworkspace file.
@@ -208,16 +231,6 @@ If you have a blank map issue, ([#118](https://github.com/airbnb/react-native-ma
208231

209232
If google logo/markers/polylines etc are displayed, this is likely an API key issue. Verify your API keys and their restrictions. Ensure the native `provideAPIKey` call is the first line of `didFinishLaunchingWithOptions`.
210233

211-
If you have ran 'react-native link` by mistake:
212-
213-
1. delete node_modules
214-
2. delete ios/Pods
215-
3. delete ios/Podfile.lock
216-
4. open Xcode and delete `AIRMaps.xcodeproj` from Libraries if it exists
217-
5. in Build Phases -> Link Binary With Libraries delete `libAIRMaps.a` if it exists
218-
6. delete ios/build folder
219-
7. start again with the installation steps
220-
221234
If you use Xcode with version less than 9 you may get `use of undeclared identifier 'MKMapTypeMutedStandard'` or `Entry, ":CFBundleIdentifier", Does Not Exist` errors. In this case you have to update your Xcode.
222235

223236
### On Android:

enable-google-maps

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/bin/bash
2+
3+
cd "$(dirname "${BASH_SOURCE[0]}")"
4+
5+
GOOGLE_MAPS_INSTALL_LOCATION=$1
6+
7+
if [[ -z "$GOOGLE_MAPS_INSTALL_LOCATION" ]]; then
8+
echo "usage: enable-google-maps <google-frameworks-relative-install-dir>"
9+
exit 1
10+
fi
11+
12+
cat > lib/ios/User.xcconfig <<EOF
13+
FRAMEWORK_SEARCH_PATHS = \$(inherited) \$(SRCROOT)/../../../../$GOOGLE_MAPS_INSTALL_LOCATION
14+
GCC_PREPROCESSOR_DEFINITIONS = \$(inherited) HAVE_GOOGLE_MAPS=1
15+
EOF

lib/ios/AirGoogleMaps/AIRDummyView.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,14 @@
55
// Created by Gil Birman on 10/4/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <UIKit/UIKit.h>
911

1012

1113
@interface AIRDummyView : UIView
1214
@property (nonatomic, weak) UIView *view;
1315
- (instancetype)initWithView:(UIView*)view;
1416
@end
17+
18+
#endif

lib/ios/AirGoogleMaps/AIRDummyView.m

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gil Birman on 10/4/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <Foundation/Foundation.h>
911
#import "AIRDummyView.h"
1012

@@ -17,3 +19,5 @@ - (instancetype)initWithView:(UIView*)view
1719
return self;
1820
}
1921
@end
22+
23+
#endif

lib/ios/AirGoogleMaps/AIRGMSMarker.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gil Birman on 9/5/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <GoogleMaps/GoogleMaps.h>
911
#import <React/UIView+React.h>
1012

@@ -21,3 +23,5 @@
2123
@required
2224
-(void)didTapMarker;
2325
@end
26+
27+
#endif

lib/ios/AirGoogleMaps/AIRGMSMarker.m

+4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
// Created by Gil Birman on 9/5/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import "AIRGMSMarker.h"
911

1012
@implementation AIRGMSMarker
1113

1214
@end
15+
16+
#endif

lib/ios/AirGoogleMaps/AIRGMSPolygon.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gerardo Pacheco 02/05/2017.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <GoogleMaps/GoogleMaps.h>
911
#import <React/UIView+React.h>
1012

@@ -14,3 +16,5 @@
1416
@property (nonatomic, strong) NSString *identifier;
1517
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
1618
@end
19+
20+
#endif

lib/ios/AirGoogleMaps/AIRGMSPolygon.m

+4
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@
55
// Created by Gerardo Pacheco 02/05/2017.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import "AIRGMSPolygon.h"
911

1012
@implementation AIRGMSPolygon
1113

1214
@end
15+
16+
#endif

lib/ios/AirGoogleMaps/AIRGMSPolyline.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Guilherme Pontes 04/05/2017.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <GoogleMaps/GoogleMaps.h>
911
#import <React/UIView+React.h>
1012

@@ -14,3 +16,5 @@
1416
@property (nonatomic, strong) NSString *identifier;
1517
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
1618
@end
19+
20+
#endif

lib/ios/AirGoogleMaps/AIRGMSPolyline.m

+4
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,11 @@
55
// Created by Guilherme Pontes 04/05/2017.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import "AIRGMSPolyline.h"
911

1012
@implementation AIRGMSPolyline
1113
@end
14+
15+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMap.h

+4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gil Birman on 9/1/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import <UIKit/UIKit.h>
911
#import <React/RCTComponent.h>
1012
#import <React/RCTBridge.h>
@@ -65,3 +67,5 @@
6567
+ (GMSCameraPosition*)makeGMSCameraPositionFromMap:(GMSMapView *)map andMKCoordinateRegion:(MKCoordinateRegion)region;
6668

6769
@end
70+
71+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMap.m

+28-4
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
// Created by Gil Birman on 9/1/16.
66
//
77

8+
#ifdef HAVE_GOOGLE_MAPS
9+
810
#import "AIRGoogleMap.h"
911
#import "AIRGoogleMapMarker.h"
1012
#import "AIRGoogleMapMarkerManager.h"
@@ -14,15 +16,27 @@
1416
#import "AIRGoogleMapUrlTile.h"
1517
#import "AIRGoogleMapOverlay.h"
1618
#import <GoogleMaps/GoogleMaps.h>
17-
#import <Google-Maps-iOS-Utils/GMUKMLParser.h>
18-
#import <Google-Maps-iOS-Utils/GMUPlacemark.h>
19-
#import <Google-Maps-iOS-Utils/GMUPoint.h>
20-
#import <Google-Maps-iOS-Utils/GMUGeometryRenderer.h>
2119
#import <MapKit/MapKit.h>
2220
#import <React/UIView+React.h>
2321
#import <React/RCTBridge.h>
2422
#import "RCTConvert+AirMap.h"
2523

24+
#ifdef HAVE_GOOGLE_MAPS_UTILS
25+
#import <Google-Maps-iOS-Utils/GMUKMLParser.h>
26+
#import <Google-Maps-iOS-Utils/GMUPlacemark.h>
27+
#import <Google-Maps-iOS-Utils/GMUPoint.h>
28+
#import <Google-Maps-iOS-Utils/GMUGeometryRenderer.h>
29+
#define REQUIRES_GOOGLE_MAPS_UTILS(feature) do {} while (0)
30+
#else
31+
#define GMUKMLParser void
32+
#define GMUPlacemark void
33+
#define REQUIRES_GOOGLE_MAPS_UTILS(feature) do { \
34+
[NSException raise:@"ReactNativeMapsDependencyMissing" \
35+
format:@"Use of " feature "requires Google-Maps-iOS-Utils, you must install via CocoaPods to use this feature"]; \
36+
} while (0)
37+
#endif
38+
39+
2640
id regionAsJSON(MKCoordinateRegion region) {
2741
return @{
2842
@"latitude": [NSNumber numberWithDouble:region.center.latitude],
@@ -496,6 +510,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
496510
}
497511

498512
+ (NSString *)GetIconUrl:(GMUPlacemark *) marker parser:(GMUKMLParser *) parser {
513+
#ifdef HAVE_GOOGLE_MAPS_UTILS
499514
if (marker.style.styleID != nil) {
500515
for (GMUStyle *style in parser.styles) {
501516
if (style.styleID == marker.style.styleID) {
@@ -505,13 +520,17 @@ + (NSString *)GetIconUrl:(GMUPlacemark *) marker parser:(GMUKMLParser *) parser
505520
}
506521

507522
return marker.style.iconUrl;
523+
#else
524+
REQUIRES_GOOGLE_MAPS_UTILS("GetIconUrl:parser:"); return @"";
525+
#endif
508526
}
509527

510528
- (NSString *)KmlSrc {
511529
return _kmlSrc;
512530
}
513531

514532
- (void)setKmlSrc:(NSString *)kmlUrl {
533+
#ifdef HAVE_GOOGLE_MAPS_UTILS
515534

516535
_kmlSrc = kmlUrl;
517536

@@ -563,6 +582,11 @@ - (void)setKmlSrc:(NSString *)kmlUrl {
563582

564583
id event = @{@"markers": markers};
565584
if (self.onKmlReady) self.onKmlReady(event);
585+
#else
586+
REQUIRES_GOOGLE_MAPS_UTILS();
587+
#endif
566588
}
567589

568590
@end
591+
592+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCallout.h

+4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
//
77
//
88

9+
#ifdef HAVE_GOOGLE_MAPS
10+
911
#import <UIKit/UIKit.h>
1012
#import <React/RCTView.h>
1113

1214
@interface AIRGoogleMapCallout : UIView
1315
@property (nonatomic, assign) BOOL tooltip;
1416
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
1517
@end
18+
19+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCallout.m

+4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,14 @@
66
//
77
//
88

9+
#ifdef HAVE_GOOGLE_MAPS
10+
911
#import "AIRGoogleMapCallout.h"
1012
#import <React/RCTUtils.h>
1113
#import <React/RCTView.h>
1214
#import <React/RCTBridge.h>
1315

1416
@implementation AIRGoogleMapCallout
1517
@end
18+
19+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCalloutManager.h

+5
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,13 @@
55
// Created by Gil Birman on 9/6/16.
66
//
77
//
8+
9+
#ifdef HAVE_GOOGLE_MAPS
10+
811
#import <React/RCTViewManager.h>
912

1013
@interface AIRGoogleMapCalloutManager : RCTViewManager
1114

1215
@end
16+
17+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCalloutManager.m

+4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
//
77
//
88

9+
#ifdef HAVE_GOOGLE_MAPS
10+
911
#import "AIRGoogleMapCalloutManager.h"
1012
#import "AIRGoogleMapCallout.h"
1113
#import <React/RCTView.h>
@@ -23,3 +25,5 @@ - (UIView *)view
2325
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)
2426

2527
@end
28+
29+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCircle.h

+4
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
// Created by Nick Italiano on 10/24/16.
55
//
66

7+
#ifdef HAVE_GOOGLE_MAPS
8+
79
#import <GoogleMaps/GoogleMaps.h>
810
#import "AIRMapCoordinate.h"
911

@@ -18,3 +20,5 @@
1820
@property (nonatomic, assign) int zIndex;
1921

2022
@end
23+
24+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCircle.m

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
//
44
// Created by Nick Italiano on 10/24/16.
55
//
6+
7+
#ifdef HAVE_GOOGLE_MAPS
68
#import <UIKit/UIKit.h>
79
#import "AIRGoogleMapCircle.h"
810
#import <GoogleMaps/GoogleMaps.h>
@@ -55,3 +57,5 @@ -(void)setZIndex:(int)zIndex
5557
}
5658

5759
@end
60+
61+
#endif

lib/ios/AirGoogleMaps/AIRGoogleMapCircleManager.h

+4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44
// Created by Nick Italiano on 10/24/16.
55
//
66

7+
#ifdef HAVE_GOOGLE_MAPS
8+
79
#import <React/RCTViewManager.h>
810

911
@interface AIRGoogleMapCircleManager : RCTViewManager
1012

1113
@end
14+
15+
#endif

0 commit comments

Comments
 (0)