Video guide available here: https://youtu.be/XTwpYtNTV48
react-native init MyMap
cd MyMap
yarn add react-native-maps
react-native link react-native-maps
Step 03: Setup iOS project (Make sure you have Cocoapods installed on your Mac)
cd ios
pod init
Open Podfile
in your vscode (atom, phpstorm etc...)
# Podfile content
source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0'
target 'MyMap' do
react_native_path = "../node_modules/react-native"
pod "Yoga", :path => "#{react_native_path}/ReactCommon/yoga"
pod "React", :path => react_native_path
pod 'GoogleMaps' # <~~ remove this line if you do not want to support GoogleMaps on iOS
end
pod install
open MyMap.xcworkspace
open .
Your project will be open in Xcode, drag n drop AirGoogleMaps
dir in MyMap/node_modules/react-native-maps/lib/ios
to your Xcode project.
Go to Google console, choose or create new project, go to library then enable 2 libraries:
- Google Map SDK for iOS
- Google Map Android API
Then create new Credentials
key
...
#import "AppDelegate.h"
#import <React/RCTBundleURLProvider.h>
#import <React/RCTRootView.h>
@import GoogleMaps; # INSERT THIS LINE
@implementation AppDelegate
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
NSURL *jsCodeLocation;
[GMSServices provideAPIKey:@"YOUR_KEY"]; # INSERT THIS LINE
jsCodeLocation = [[RCTBundleURLProvider sharedSettings] jsBundleURLForBundleRoot:@"index.ios" fallbackResource:nil];
...
You're done setting up iOS project, you can now react-native run-ios
dependencies {
...
// Paste these line
compile(project(':react-native-maps')){
exclude group: 'com.google.android.gms', module: 'play-services-base'
exclude group: 'com.google.android.gms', module: 'play-services-maps'
}
compile 'com.google.android.gms:play-services-base:10.0.1'
compile 'com.google.android.gms:play-services-maps:10.0.1'
}
<application>
<!-- You will only need to add this meta-data tag, but make sure it's a child of application -->
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR GOOGLE MAPS API KEY HERE"/>
</application>
MIT License
Copyright (c) 2017 anhtuank7c
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.