Skip to content

Commit 887b065

Browse files
committed
docs: update README and setup documentation for iOS Google Maps configuration
1 parent bf4184c commit 887b065

18 files changed

Lines changed: 258 additions & 22 deletions

README.md

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ export default {
181181
| Option | Platform | Description |
182182
| -------------------------- | ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
183183
| `googleMapsApiKey` | iOS + Android | Shared fallback when platform-specific keys are omitted. |
184-
| `iosGoogleMapsApiKey` | iOS | Injects `GoogleMapsIosApiKey` into `Info.plist` for `provider="google"`. |
184+
| `iosGoogleMapsApiKey` | iOS | Injects `GoogleMapsIosApiKey` into `Info.plist` and sets `betterMaps.iosGoogleProvider` in `Podfile.properties.json` so the Google Maps SDK is linked. |
185185
| `androidGoogleMapsApiKey` | Android | Injects `com.google.android.geo.API_KEY` metadata. |
186186
| `locationPermission` | iOS + Android | Foreground location message. Injects `NSLocationWhenInUseUsageDescription` plus `ACCESS_FINE_LOCATION` + `ACCESS_COARSE_LOCATION`. Pass `false` or omit to skip. |
187187
| `locationAlwaysPermission` | iOS + Android | Background location message. Injects `NSLocationAlwaysAndWhenInUseUsageDescription` plus `ACCESS_BACKGROUND_LOCATION`; also supplies foreground usage strings and permissions when `locationPermission` is omitted. Pass `false` or omit to skip. |
@@ -398,7 +398,28 @@ The example app uses the config plugin. It reads `GOOGLE_MAPS_IOS_API_KEY` and `
398398

399399
### Bare React Native
400400

401-
- iOS: add a `GoogleMapsIosApiKey` string to `Info.plist`.
401+
On iOS, `provider="google"` needs **two** host-app settings that the config plugin normally writes together:
402+
403+
1. **Runtime API key**`GoogleMapsIosApiKey` in `Info.plist` (read when the map mounts).
404+
2. **SDK linkage**`"betterMaps.iosGoogleProvider": "true"` in `ios/Podfile.properties.json` (read by `react-native-better-maps.podspec` during `pod install` to add the `GoogleMaps` pod).
405+
406+
In a bare workflow the plugin does not run, so configure both manually:
407+
408+
```xml
409+
<!-- Info.plist -->
410+
<key>GoogleMapsIosApiKey</key>
411+
<string>YOUR_API_KEY</string>
412+
```
413+
414+
```json
415+
// ios/Podfile.properties.json
416+
{
417+
"betterMaps.iosGoogleProvider": "true"
418+
}
419+
```
420+
421+
Then run `pod install` from `ios/`.
422+
402423
- Android: add `com.google.android.geo.API_KEY` metadata to `AndroidManifest.xml`.
403424

404425
### Google Map ID
@@ -538,6 +559,7 @@ See [example/.env.example](example/.env.example) for the supported environment v
538559
| Problem | Solution |
539560
| ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
540561
| Map is blank when using Google Maps | Add a Google Maps API key through the Expo config plugin, `GoogleMapsIosApiKey` in `Info.plist`, or `com.google.android.geo.API_KEY` in `AndroidManifest.xml`. |
562+
| iOS Google Maps key set but provider errors | iOS needs both `GoogleMapsIosApiKey` in `Info.plist` **and** `"betterMaps.iosGoogleProvider": "true"` in `Podfile.properties.json`, then `pod install`. The config plugin sets both; in bare workflow or with a stale `Podfile.properties.json`, they can drift apart. |
541563
| New Architecture errors | Confirm React Native `0.78+`, New Architecture, and `react-native-nitro-modules` are installed, then rebuild the native app. |
542564
| Provider throws before rendering | Check the [supported platforms](#supported-platforms) table. `openstreetmap` and `mapbox` are reserved for future support but do not render yet. |
543565
| Expo Go does not load native maps | Use a development build after `expo prebuild`; native Nitro modules are not available in Expo Go. |

docs/expo-setup.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ module.exports = {
4242
| Option | Type | Default | Description |
4343
| -------------------------- | ----------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
4444
| `googleMapsApiKey` | `string` || Shared fallback for iOS and Android when platform-specific keys are omitted. |
45-
| `iosGoogleMapsApiKey` | `string` || Injects `GoogleMapsIosApiKey` into `Info.plist` for `provider="google"` on iOS. |
45+
| `iosGoogleMapsApiKey` | `string` || Injects `GoogleMapsIosApiKey` into `Info.plist` and sets `betterMaps.iosGoogleProvider` in `Podfile.properties.json` so the Google Maps SDK is linked on iOS. |
4646
| `androidGoogleMapsApiKey` | `string` || Injects `com.google.android.geo.API_KEY` meta-data on Android. |
4747
| `locationPermission` | `string \| false` || Foreground location message. Injects iOS `NSLocationWhenInUseUsageDescription` plus Android `ACCESS_FINE_LOCATION` and `ACCESS_COARSE_LOCATION`. |
4848
| `locationAlwaysPermission` | `string \| false` || Background location message. Injects iOS `NSLocationAlwaysAndWhenInUseUsageDescription` plus Android `ACCESS_BACKGROUND_LOCATION`; also supplies foreground usage strings and permissions when `locationPermission` is omitted. |
@@ -86,7 +86,9 @@ expo prebuild --clean
8686
The plugin injects:
8787

8888
- **Android:** `com.google.android.geo.API_KEY` meta-data (when `googleMapsApiKey` or `androidGoogleMapsApiKey` is set) and location permissions (when location options are set)
89-
- **iOS:** `GoogleMapsIosApiKey` (when `googleMapsApiKey` or `iosGoogleMapsApiKey` is set) and location usage description strings (when location options are set)
89+
- **iOS:** `GoogleMapsIosApiKey` in `Info.plist` and `betterMaps.iosGoogleProvider` in `Podfile.properties.json` (when `googleMapsApiKey` or `iosGoogleMapsApiKey` is set), plus location usage description strings (when location options are set)
90+
91+
On iOS, the API key and pod linkage are separate artifacts. The plugin keeps them in sync during prebuild. If you later remove Google Maps keys from the plugin config, re-run `expo prebuild` so `Podfile.properties.json` is updated and run `pod install` — a stale `"betterMaps.iosGoogleProvider": "true"` can leave the SDK linked after you stop providing a key. Bare React Native apps without the plugin must set both manually; see [Bare React Native](../README.md#bare-react-native) in the README.
9092

9193
## Run
9294

@@ -111,6 +113,7 @@ The example's `prebuild` script builds the plugin (`build:plugin`) before runnin
111113
| Symptom | Fix |
112114
| ------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------ |
113115
| Blank Google map | Ensure `googleMapsApiKey` or the platform-specific Google Maps key is set, then run `expo prebuild` again. |
116+
| iOS Google Maps key present but provider fails | iOS needs `GoogleMapsIosApiKey` in `Info.plist` **and** `"betterMaps.iosGoogleProvider": "true"` in `Podfile.properties.json`, then `pod install`. Re-run prebuild after changing plugin keys so both stay aligned. |
114117
| Location dot not showing | Set `locationPermission` or `locationAlwaysPermission` in the plugin options and re-run prebuild. |
115118
| Plugin not found | Confirm `react-native-better-maps` is installed and listed in `plugins`. |
116119
| `Cannot find module './plugin/build/index'` | Run `bun run build:plugin` in the package (or `bun run build` from the repo root) before prebuild when using a workspace link. |

example/app.config.js

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,6 @@ function readEnv(name) {
55
return value == null || value.trim() === '' ? undefined : value;
66
}
77

8-
const googleMapsApiKey = readEnv('GOOGLE_MAPS_API_KEY');
9-
const iosGoogleMapsApiKey =
10-
readEnv('GOOGLE_MAPS_IOS_API_KEY') ?? googleMapsApiKey;
11-
const androidGoogleMapsApiKey =
12-
readEnv('GOOGLE_MAPS_ANDROID_API_KEY') ?? googleMapsApiKey;
13-
148
/** @type {import('expo/config').ExpoConfig} */
159
module.exports = {
1610
expo: {
@@ -20,8 +14,9 @@ module.exports = {
2014
[
2115
'react-native-better-maps',
2216
{
23-
iosGoogleMapsApiKey,
24-
androidGoogleMapsApiKey,
17+
googleMapsApiKey: readEnv('GOOGLE_MAPS_API_KEY'),
18+
iosGoogleMapsApiKey: readEnv('GOOGLE_MAPS_IOS_API_KEY'),
19+
androidGoogleMapsApiKey: readEnv('GOOGLE_MAPS_ANDROID_API_KEY'),
2520
locationPermission:
2621
'Allow $(PRODUCT_NAME) to use your location for map features.',
2722
},

package/ios/Camera+GMSCameraPosition.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(GoogleMaps)
12
import CoreLocation
23
import GoogleMaps
34

@@ -24,3 +25,4 @@ extension GMSCameraPosition {
2425
)
2526
}
2627
}
28+
#endif

package/ios/GMSMapView+VisibleRegion.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(GoogleMaps)
12
import GoogleMaps
23
import NitroModules
34

@@ -22,3 +23,4 @@ extension CLLocationCoordinate2D {
2223
Coordinate(latitude: latitude, longitude: longitude)
2324
}
2425
}
26+
#endif

package/ios/GoogleMapOverlayController.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(GoogleMaps)
12
import GoogleMaps
23
import MapKit
34
import UIKit
@@ -477,3 +478,4 @@ private extension Array where Element == Coordinate {
477478
return path
478479
}
479480
}
481+
#endif

package/ios/GoogleMapProviderAdapter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(GoogleMaps)
12
import CoreLocation
23
import GoogleMaps
34
import MapKit
@@ -585,3 +586,4 @@ extension GoogleMapProviderAdapter: GMSMapViewDelegate {
585586
notifyMapReadyIfNeeded()
586587
}
587588
}
589+
#endif

package/ios/GoogleMapsAPIKey.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
import Foundation
2+
3+
#if canImport(GoogleMaps)
24
import GoogleMaps
35

46
enum GoogleMapsAPIKey {
@@ -20,15 +22,19 @@ enum GoogleMapsAPIKey {
2022
configuredKey = key
2123
}
2224
}
25+
#endif
2326

2427
enum MapProviderConfigurationError: LocalizedError {
2528
case missingGoogleMapsIosApiKey
29+
case googleMapsSdkNotLinked
2630
case unsupportedIOSProvider(MapProvider)
2731

2832
var errorDescription: String? {
2933
switch self {
3034
case .missingGoogleMapsIosApiKey:
3135
return "react-native-better-maps: provider=\"google\" on iOS requires GoogleMapsIosApiKey in the host app Info.plist."
36+
case .googleMapsSdkNotLinked:
37+
return "react-native-better-maps: provider=\"google\" on iOS requires iosGoogleMapsApiKey or googleMapsApiKey in the react-native-better-maps config plugin to link the Google Maps SDK, then run pod install."
3238
case let .unsupportedIOSProvider(provider):
3339
return "Map provider \"\(provider)\" is not supported on iOS."
3440
}

package/ios/HybridMapView.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -376,11 +376,17 @@ final class HybridMapView: HybridMapViewSpec {
376376
case .apple:
377377
return AppleMapProviderAdapter()
378378
case .google:
379+
#if canImport(GoogleMaps)
379380
do {
380381
return try GoogleMapProviderAdapter(googleMapId: withStateLock { self._state.googleMapId })
381382
} catch {
382383
return UnavailableMapProviderAdapter(error: error)
383384
}
385+
#else
386+
return UnavailableMapProviderAdapter(
387+
error: MapProviderConfigurationError.googleMapsSdkNotLinked
388+
)
389+
#endif
384390
case .openstreetmap, .mapbox:
385391
return UnavailableMapProviderAdapter(
386392
error: MapProviderConfigurationError.unsupportedIOSProvider(provider)

package/ios/MapType+GMSMapViewType.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#if canImport(GoogleMaps)
12
import GoogleMaps
23

34
extension MapType {
@@ -14,3 +15,4 @@ extension MapType {
1415
}
1516
}
1617
}
18+
#endif

0 commit comments

Comments
 (0)