Skip to content

Commit

Permalink
Update installation.md for RN 0.60+ (react-native-maps#2968)
Browse files Browse the repository at this point in the history
* Update installation.md

Update for React Native 0.60+

* fix: unnecessary information

Delete example

* fix: missing information

Add missing pod install after editing Podfile

* fix: numbering was wrong
  • Loading branch information
schwamic authored and christopherdro committed Jul 18, 2019
1 parent f9fef92 commit fcc3858
Showing 1 changed file with 46 additions and 28 deletions.
74 changes: 46 additions & 28 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,46 @@
Install the library from npm:

```sh
npm install react-native-maps --save
npm install react-native-maps --save-exact
yarn add react-native-maps -E
```

The library ships with platform native code that needs to be compiled
together with React Native. This requires you to configure your build
tools.

Since React Native 0.60 and higher, [autolinking](https://github.com/react-native-community/cli/blob/master/docs/autolinking.md) makes the installation process simpler.

The actual map implementation depends on the platform. On Android, one
has to use [Google
Maps](https://developers.google.com/maps/documentation/), which in turn
requires you to obtain an API key for the [Android
requires you to obtain an [API key for the Android
SDK](https://developers.google.com/maps/documentation/android-sdk/signup).

On iOS, one can choose between Google Maps or the native [Apple
Maps](https://developer.apple.com/documentation/mapkit/) implementation.

When using Google Maps on iOS, you need to also register for the [iOS
When using Google Maps on iOS, you need also to obtain an [API key for the iOS
SDK](https://developers.google.com/maps/documentation/ios-sdk/get-api-key)
and include the Google Maps library in your build. The native Apple Maps
based implementation works out-of-the-box and is therefore simpler to
use at the price of missing some of the features supported by the Google
Maps backend.

> **WARNING**: Before you can start using the Google Maps Platform APIs and SDKs, you must sign up and create a [billing account](https://developers.google.com/maps/gmp-get-started#create-billing-account)!
---

## Build configuration on iOS

### Using React Native Link
### Using React Native Link (React Native 0.59 and lower)

Run `react-native link react-native-maps` after which you should be able
to use this library on iOS. Note that by default this will use Apple
Maps and you will miss some of the features provided by Google (see the
instruction on manually enabling Google Maps below).

### Using CocoaPods
### Using CocoaPods (React Native 0.59 and lower)

> If the CocoaPods package manager is new to you, please first review
> its [installation guide](https://guides.cocoapods.org/using/getting-started.html)
Expand Down Expand Up @@ -108,7 +115,14 @@ pod install

and open the produced workspace file (`.xcworkspace`) in XCode to build your project.

### Enabling Google Maps on iOS
### Using CocoaPods (React Native 0.60 and higher)

```sh
cd ios
pod install
```

### Enabling Google Maps on iOS (React Native all versions)

If you want to enable Google Maps on iOS, obtain the Google API key and
edit your `AppDelegate.m` as follows:
Expand All @@ -127,12 +141,12 @@ edit your `AppDelegate.m` as follows:
The `[GMSServices provideAPIKey]` should be the **first call** of the method.
Then, do either of the following
Then, do either of the following:
1. If you are using CocoaPods to manage your dependecies, uncomment the
a) (React Native 0.59 and lower) If you are using CocoaPods to manage your dependecies, uncomment the
lines related to Google Maps from the `Podfile` and run `pod install`.
2. If you used React Native link, you may include Google Maps manually as a
b) (React Native 0.59 and lower) If you used React Native link, you may include Google Maps manually as a
XCode framework following the instructions from [SDK docs -> Install
manually](https://developers.google.com/maps/documentation/ios-sdk/start). Then, to link this library to the framework, add the following to your
`package.json` and replace the
Expand All @@ -152,32 +166,32 @@ by adding a `/**` at the end of the provided path (e.g. `"./node_modules/react-n
Re-run `npm install` or `yarn` to ensure the `postinstall` script is run.
3. Import and add `{PROVIDER_GOOGLE}` to your JavaScript:
```javascript
import MapView, { PROVIDER_GOOGLE } from 'react-native-maps';
...
<MapView
provider={PROVIDER_GOOGLE}
style={styles.map}
...
>
```
c) (React Native 0.60 and higher) Add the following to your Podfile above the `use_native_modules!` function and run `pod install` in the ios folder:
```ruby
# React Native Maps dependencies
pod 'react-native-google-maps', path: rn_maps_path
pod 'GoogleMaps'
pod 'Google-Maps-iOS-Utils'
```

That's it, you made it! 👍

---


## Build configuration on Android

Ensure your build files match the following requirements:

1. Define the `react-native-maps` project in `android/settings.gradle`:
1. (React Native 0.59 and lower) Define the `react-native-maps` project in `android/settings.gradle`:

```groovy
...
include ':react-native-maps'
project(':react-native-maps').projectDir = new File(rootProject.projectDir, '../node_modules/react-native-maps/lib/android')
```

2. Add the `react-native-maps` as an dependency of your app in `android/app/build.gradle`:
2. (React Native 0.59 and lower) Add the `react-native-maps` as an dependency of your app in `android/app/build.gradle`:

```groovy
...
Expand All @@ -187,7 +201,7 @@ dependencies {
}
```

If you've defined *[project-wide
3.1 (React Native all versions) If you've defined *[project-wide
properties](https://developer.android.com/studio/build/gradle-tips.html)*
(**recommended**) in your root `build.gradle`, this library will detect
the presence of the following properties:
Expand All @@ -209,7 +223,7 @@ ext {
}
```

If you do **not** have *project-wide properties* defined and have a
3.2 (React Native all versions) If you do **not** have *project-wide properties* defined and have a
different play-services version than the one included in this library,
use the following instead (switch 10.0.1 for the desired version):

Expand All @@ -226,7 +240,7 @@ dependencies {
}
```

3. Specify your Google Maps API Key:
4. (React Native all versions) Specify your Google Maps API Key:

Add your API key to your manifest file (`android/app/src/main/AndroidManifest.xml`):

Expand All @@ -250,7 +264,7 @@ dependencies {
Source: https://developers.google.com/maps/documentation/android-api/signup

4. Add `import com.airbnb.android.react.maps.MapsPackage;` and `new MapsPackage()` in your `MainApplication.java` :
5. (React Native 0.59 and lower) Add `import com.airbnb.android.react.maps.MapsPackage;` and `new MapsPackage()` in your `MainApplication.java` :

```java
import com.airbnb.android.react.maps.MapsPackage;
Expand All @@ -264,14 +278,18 @@ import com.airbnb.android.react.maps.MapsPackage;
}
```

5. Ensure that you have Google Play Services installed:
6. (React Native all versions) Ensure that you have Google Play Services installed:

* For the Genymotion emulator, you can follow [these instructions](https://www.genymotion.com/help/desktop/faq/#google-play-services).
* For a physical device you need to search on Google for 'Google Play
Services'. There will be a link that takes you to the Play Store and
from there you will see a button to update it (do not search within the
Play Store).

That's it, you made it! :+1:

---

## Troubleshooting

### The map background is blank (Google Maps)
Expand Down

0 comments on commit fcc3858

Please sign in to comment.