Skip to content

Commit

Permalink
Enable custom configuration for iOS maps
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wbyoung committed Aug 24, 2018
1 parent c3b3802 commit 1ce5ea3
Show file tree
Hide file tree
Showing 45 changed files with 240 additions and 21 deletions.
43 changes: 28 additions & 15 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,20 +80,24 @@ post_install do |installer|
end
~~~

## iOS - ReactNative Link

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

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

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

## If you want to use Google maps


Add to `ios/_YOUR_PROJECT_NAME_/AppDelegate.m:

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

@implementation AppDelegate
...
Expand All @@ -106,6 +110,25 @@ Add to `ios/_YOUR_PROJECT_NAME_/AppDelegate.m:
This should be the **first line** of the method.
#### If you are not using CocoaPods
If you installed via `react-native-link`, add the following to your
`package.json` and replace the `REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL`
with the relative path from your project root to the directory in which you
installed the Google Maps frameworks:
```json
{
"name": "your-app",
"scripts": {
"postinstall": "./node_modules/react-native-maps/enable-google-maps REPLACE_ME_RELATIVE_PATH_TO_GOOGLE_MAPS_INSTALL"
}
}
```

Re-run `npm install` or `yarn` to ensure the `postinstall` script is run.


## Notes on running on a real ios device

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.
Expand Down Expand Up @@ -208,16 +231,6 @@ If you have a blank map issue, ([#118](https://github.com/airbnb/react-native-ma

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`.

If you have ran 'react-native link` by mistake:

1. delete node_modules
2. delete ios/Pods
3. delete ios/Podfile.lock
4. open Xcode and delete `AIRMaps.xcodeproj` from Libraries if it exists
5. in Build Phases -> Link Binary With Libraries delete `libAIRMaps.a` if it exists
6. delete ios/build folder
7. start again with the installation steps

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.

### On Android:
Expand Down
15 changes: 15 additions & 0 deletions enable-google-maps
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

cd "$(dirname "${BASH_SOURCE[0]}")"

GOOGLE_MAPS_INSTALL_LOCATION=$1

if [[ -z "$GOOGLE_MAPS_INSTALL_LOCATION" ]]; then
echo "usage: enable-google-maps <google-frameworks-relative-install-dir>"
exit 1
fi

cat > lib/ios/User.xcconfig <<EOF
FRAMEWORK_SEARCH_PATHS = \$(inherited) \$(SRCROOT)/../../../../$GOOGLE_MAPS_INSTALL_LOCATION
GCC_PREPROCESSOR_DEFINITIONS = \$(inherited) HAVE_GOOGLE_MAPS=1
EOF
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRDummyView.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@
// Created by Gil Birman on 10/4/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <UIKit/UIKit.h>


@interface AIRDummyView : UIView
@property (nonatomic, weak) UIView *view;
- (instancetype)initWithView:(UIView*)view;
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRDummyView.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Gil Birman on 10/4/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <Foundation/Foundation.h>
#import "AIRDummyView.h"

Expand All @@ -17,3 +19,5 @@ - (instancetype)initWithView:(UIView*)view
return self;
}
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSMarker.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Gil Birman on 9/5/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <GoogleMaps/GoogleMaps.h>
#import <React/UIView+React.h>

Expand All @@ -21,3 +23,5 @@
@required
-(void)didTapMarker;
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSMarker.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Gil Birman on 9/5/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGMSMarker.h"

@implementation AIRGMSMarker

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSPolygon.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Gerardo Pacheco 02/05/2017.
//

#ifdef HAVE_GOOGLE_MAPS

#import <GoogleMaps/GoogleMaps.h>
#import <React/UIView+React.h>

Expand All @@ -14,3 +16,5 @@
@property (nonatomic, strong) NSString *identifier;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSPolygon.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,12 @@
// Created by Gerardo Pacheco 02/05/2017.
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGMSPolygon.h"

@implementation AIRGMSPolygon

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSPolyline.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Guilherme Pontes 04/05/2017.
//

#ifdef HAVE_GOOGLE_MAPS

#import <GoogleMaps/GoogleMaps.h>
#import <React/UIView+React.h>

Expand All @@ -14,3 +16,5 @@
@property (nonatomic, strong) NSString *identifier;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGMSPolyline.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@
// Created by Guilherme Pontes 04/05/2017.
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGMSPolyline.h"

@implementation AIRGMSPolyline
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMap.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Gil Birman on 9/1/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <UIKit/UIKit.h>
#import <React/RCTComponent.h>
#import <React/RCTBridge.h>
Expand Down Expand Up @@ -65,3 +67,5 @@
+ (GMSCameraPosition*)makeGMSCameraPositionFromMap:(GMSMapView *)map andMKCoordinateRegion:(MKCoordinateRegion)region;

@end

#endif
32 changes: 28 additions & 4 deletions lib/ios/AirGoogleMaps/AIRGoogleMap.m
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
// Created by Gil Birman on 9/1/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGoogleMap.h"
#import "AIRGoogleMapMarker.h"
#import "AIRGoogleMapMarkerManager.h"
Expand All @@ -14,15 +16,27 @@
#import "AIRGoogleMapUrlTile.h"
#import "AIRGoogleMapOverlay.h"
#import <GoogleMaps/GoogleMaps.h>
#import <Google-Maps-iOS-Utils/GMUKMLParser.h>
#import <Google-Maps-iOS-Utils/GMUPlacemark.h>
#import <Google-Maps-iOS-Utils/GMUPoint.h>
#import <Google-Maps-iOS-Utils/GMUGeometryRenderer.h>
#import <MapKit/MapKit.h>
#import <React/UIView+React.h>
#import <React/RCTBridge.h>
#import "RCTConvert+AirMap.h"

#ifdef HAVE_GOOGLE_MAPS_UTILS
#import <Google-Maps-iOS-Utils/GMUKMLParser.h>
#import <Google-Maps-iOS-Utils/GMUPlacemark.h>
#import <Google-Maps-iOS-Utils/GMUPoint.h>
#import <Google-Maps-iOS-Utils/GMUGeometryRenderer.h>
#define REQUIRES_GOOGLE_MAPS_UTILS(feature) do {} while (0)
#else
#define GMUKMLParser void
#define GMUPlacemark void
#define REQUIRES_GOOGLE_MAPS_UTILS(feature) do { \
[NSException raise:@"ReactNativeMapsDependencyMissing" \
format:@"Use of " feature "requires Google-Maps-iOS-Utils, you must install via CocoaPods to use this feature"]; \
} while (0)
#endif


id regionAsJSON(MKCoordinateRegion region) {
return @{
@"latitude": [NSNumber numberWithDouble:region.center.latitude],
Expand Down Expand Up @@ -496,6 +510,7 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}

+ (NSString *)GetIconUrl:(GMUPlacemark *) marker parser:(GMUKMLParser *) parser {
#ifdef HAVE_GOOGLE_MAPS_UTILS
if (marker.style.styleID != nil) {
for (GMUStyle *style in parser.styles) {
if (style.styleID == marker.style.styleID) {
Expand All @@ -505,13 +520,17 @@ + (NSString *)GetIconUrl:(GMUPlacemark *) marker parser:(GMUKMLParser *) parser
}

return marker.style.iconUrl;
#else
REQUIRES_GOOGLE_MAPS_UTILS("GetIconUrl:parser:"); return @"";
#endif
}

- (NSString *)KmlSrc {
return _kmlSrc;
}

- (void)setKmlSrc:(NSString *)kmlUrl {
#ifdef HAVE_GOOGLE_MAPS_UTILS

_kmlSrc = kmlUrl;

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

id event = @{@"markers": markers};
if (self.onKmlReady) self.onKmlReady(event);
#else
REQUIRES_GOOGLE_MAPS_UTILS();
#endif
}

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCallout.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
//
//

#ifdef HAVE_GOOGLE_MAPS

#import <UIKit/UIKit.h>
#import <React/RCTView.h>

@interface AIRGoogleMapCallout : UIView
@property (nonatomic, assign) BOOL tooltip;
@property (nonatomic, copy) RCTBubblingEventBlock onPress;
@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCallout.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,14 @@
//
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGoogleMapCallout.h"
#import <React/RCTUtils.h>
#import <React/RCTView.h>
#import <React/RCTBridge.h>

@implementation AIRGoogleMapCallout
@end

#endif
5 changes: 5 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCalloutManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,13 @@
// Created by Gil Birman on 9/6/16.
//
//

#ifdef HAVE_GOOGLE_MAPS

#import <React/RCTViewManager.h>

@interface AIRGoogleMapCalloutManager : RCTViewManager

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCalloutManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
//
//

#ifdef HAVE_GOOGLE_MAPS

#import "AIRGoogleMapCalloutManager.h"
#import "AIRGoogleMapCallout.h"
#import <React/RCTView.h>
Expand All @@ -23,3 +25,5 @@ - (UIView *)view
RCT_EXPORT_VIEW_PROPERTY(onPress, RCTBubblingEventBlock)

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCircle.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
// Created by Nick Italiano on 10/24/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <GoogleMaps/GoogleMaps.h>
#import "AIRMapCoordinate.h"

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

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCircle.m
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
//
// Created by Nick Italiano on 10/24/16.
//

#ifdef HAVE_GOOGLE_MAPS
#import <UIKit/UIKit.h>
#import "AIRGoogleMapCircle.h"
#import <GoogleMaps/GoogleMaps.h>
Expand Down Expand Up @@ -55,3 +57,5 @@ -(void)setZIndex:(int)zIndex
}

@end

#endif
4 changes: 4 additions & 0 deletions lib/ios/AirGoogleMaps/AIRGoogleMapCircleManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@
// Created by Nick Italiano on 10/24/16.
//

#ifdef HAVE_GOOGLE_MAPS

#import <React/RCTViewManager.h>

@interface AIRGoogleMapCircleManager : RCTViewManager

@end

#endif
Loading

0 comments on commit 1ce5ea3

Please sign in to comment.