First, download the library from npm:
npm install react-native-maps --save
Then you must install the native dependencies. You can use rnpm to
add native dependencies automatically:
$ rnpm link
or do it manually as described below:
- Open your project in XCode, right click on
Librariesand clickAdd Files to "Your Project Name"Look undernode_modules/react-native-maps/iosand addAIRMaps.xcodeproj. - Add
libAIRMaps.ato `Build Phases -> Link Binary With Libraries. - Click on
AIRMaps.xcodeprojinLibrariesand go theBuild Settingstab. Double click the text to the right ofHeader Search Pathsand verify that it has$(SRCROOT)/../../react-native/Reactas well as$(SRCROOT)/../../react-native/Libraries/Image- if they aren't, then add them. This is so XCode is able to find the headers that theAIRMapssource files are referring to by pointing to the header files installed within thereact-nativenode_modulesdirectory. - Whenever you want to use it within React code now you can:
var MapView = require('react-native-maps');
-
in
android/settings.gradleinclude ':app', ':react-native-maps' project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/android') -
in
android/app/build.gradleadd:dependencies { ... compile project(':react-native-maps') } -
and finally, in
android/src/main/java/com/{YOUR_APP_NAME}/MainActivity.javaadd:Newer versions of React Native
... import com.AirMaps.AirPackage; // <--- This! ... public class MainActivity extends ReactActivity { @Override protected String getMainComponentName() { return "sample"; } @Override protected boolean getUseDeveloperSupport() { return BuildConfig.DEBUG; } @Override protected List<ReactPackage> getPackages() { return Arrays.<ReactPackage>asList( new MainReactPackage(), new AirPackage() // <---- and This! ); } }Older versions of React Native
... import com.AirMaps.AirPackage; // <--- This! ... @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); mReactRootView = new ReactRootView(this); mReactInstanceManager = ReactInstanceManager.builder() .setApplication(getApplication()) .setBundleAssetName("index.android.bundle") .setJSMainModuleName("index.android") .addPackage(new MainReactPackage()) .addPackage(new AirPackage()) // <---- and This! .setUseDeveloperSupport(BuildConfig.DEBUG) .setInitialLifecycleState(LifecycleState.RESUMED) .build(); mReactRootView.startReactApplication(mReactInstanceManager, "MyApp", null); setContentView(mReactRootView); } -
specify your Google Maps API Key in your
AndroidManifest.xml:
<application
android:allowBackup="true"
android:label="@string/app_name"
android:icon="@mipmap/ic_launcher"
android:theme="@style/AppTheme">
<!-- 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>- Ensure that you have Google Play Services installed