capacitor-google-navigation 0.0.8 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -57,30 +57,47 @@ The `GoogleNavigation ~> 9.0` pod is declared in the plugin's podspec and is pul
57
57
  <string>This app uses your location for navigation, including in the background.</string>
58
58
  ```
59
59
 
60
- ### 3. Register your API key in `AppDelegate.swift`
60
+ ### 3. Register your API key
61
61
 
62
- The iOS SDK requires the key to be provided before any map or navigator is created.
62
+ #### Production (recommended)
63
63
 
64
- ```swift
65
- import UIKit
66
- import Capacitor
67
- import CapacitorGoogleNavigation
68
- import GoogleNavigation // required for GMSServices
64
+ Store the key in `Info.plist` under the key `GoogleNavigationAPIKey`. The plugin reads it automatically — no key needs to be passed from JS.
69
65
 
70
- @UIApplicationMain
71
- class AppDelegate: UIResponder, UIApplicationDelegate {
66
+ ```xml
67
+ <key>GoogleNavigationAPIKey</key>
68
+ <string>YOUR_IOS_API_KEY</string>
69
+ ```
72
70
 
73
- func application(
74
- _ application: UIApplication,
75
- didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
76
- ) -> Bool {
77
- GMSServices.provideAPIKey("YOUR_IOS_API_KEY")
78
- return true
79
- }
80
- }
71
+ Then call `initialize()` with no key:
72
+
73
+ ```ts
74
+ await GoogleNavigation.initialize({});
75
+ ```
76
+
77
+ Keep the key out of source control by injecting it at build time via an `.xcconfig` file:
78
+
79
+ ```
80
+ // Config.xcconfig (gitignored)
81
+ GOOGLE_NAV_API_KEY = AIzaSy...
82
+ ```
83
+
84
+ ```xml
85
+ <!-- Info.plist -->
86
+ <key>GoogleNavigationAPIKey</key>
87
+ <string>$(GOOGLE_NAV_API_KEY)</string>
88
+ ```
89
+
90
+ #### Development only
91
+
92
+ You can pass the key directly from JS for quick local testing. **Do not ship this in production** — the key will be visible in your compiled JS bundle.
93
+
94
+ ```ts
95
+ await GoogleNavigation.initialize({ apiKey: 'YOUR_IOS_API_KEY' });
81
96
  ```
82
97
 
83
- > You can also pass the key via `GoogleNavigation.initialize({ apiKey })` at runtime — the plugin calls `GMSServices.provideAPIKey()` for you. Either approach works; calling it in `AppDelegate` is the earlier-initialization option.
98
+ #### Restrict your API key
99
+
100
+ In Google Cloud Console → APIs & Services → Credentials, add an **iOS app restriction** with your app's bundle ID. This ensures the key is rejected if extracted and used outside your app.
84
101
 
85
102
  ---
86
103
 
@@ -88,6 +105,8 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
88
105
 
89
106
  ### 1. Add the API key and permissions to `android/app/src/main/AndroidManifest.xml`
90
107
 
108
+ The Android Navigation SDK reads the key directly from the manifest at startup — it is never passed from JS.
109
+
91
110
  ```xml
92
111
  <manifest>
93
112
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
@@ -95,14 +114,32 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
95
114
  <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
96
115
 
97
116
  <application>
98
- <!-- Required: Navigation SDK reads this at startup -->
99
117
  <meta-data
100
118
  android:name="com.google.android.geo.API_KEY"
101
- android:value="YOUR_ANDROID_API_KEY" />
119
+ android:value="${GOOGLE_NAV_API_KEY}" />
102
120
  </application>
103
121
  </manifest>
104
122
  ```
105
123
 
124
+ Keep the key out of source control using `gradle.properties` (gitignored):
125
+
126
+ ```
127
+ # android/gradle.properties (gitignored)
128
+ GOOGLE_NAV_API_KEY=AIzaSy...
129
+ ```
130
+
131
+ Then in `android/app/build.gradle`, expose it to the manifest:
132
+
133
+ ```groovy
134
+ android {
135
+ defaultConfig {
136
+ manifestPlaceholders = [GOOGLE_NAV_API_KEY: project.findProperty("GOOGLE_NAV_API_KEY") ?: ""]
137
+ }
138
+ }
139
+ ```
140
+
141
+ Restrict the key in Google Cloud Console by adding your app's **SHA-1 certificate fingerprint** and **package name** under Android app restrictions.
142
+
106
143
  > **Important:** On Android the Navigation SDK reads the API key from `AndroidManifest.xml` — not from the `apiKey` parameter passed to `initialize()`. The `apiKey` parameter is used on iOS only.
107
144
 
108
145
  ### 2. Request location permission at runtime
@@ -59,16 +59,10 @@ public class GoogleNavigation {
59
59
  return;
60
60
  }
61
61
 
62
- Waypoint destination;
63
- try {
64
- destination = new Waypoint.Builder()
65
- .setLatLng(lat, lng)
66
- .setTitle("Destination")
67
- .build();
68
- } catch (Waypoint.UnsupportedTravelModeException e) {
69
- callback.onResult(false, "Unsupported travel mode");
70
- return;
71
- }
62
+ Waypoint destination = new Waypoint.Builder()
63
+ .setLatLng(lat, lng)
64
+ .setTitle("Destination")
65
+ .build();
72
66
 
73
67
  RoutingOptions.TravelMode mode;
74
68
  switch (travelMode) {
@@ -14,11 +14,17 @@ public class GoogleNavigationPlugin: CAPPlugin, CAPBridgedPlugin {
14
14
  private lazy var implementation = GoogleNavigation(plugin: self)
15
15
 
16
16
  @objc func initialize(_ call: CAPPluginCall) {
17
- guard let apiKey = call.getString("apiKey"), !apiKey.isEmpty else {
18
- call.reject("apiKey is required")
17
+ let jsKey = call.getString("apiKey") ?? ""
18
+ let resolvedKey = !jsKey.isEmpty
19
+ ? jsKey
20
+ : Bundle.main.object(forInfoDictionaryKey: "GoogleNavigationAPIKey") as? String ?? ""
21
+
22
+ guard !resolvedKey.isEmpty else {
23
+ call.reject("No API key found. Add GoogleNavigationAPIKey to Info.plist (recommended) or pass apiKey to initialize().")
19
24
  return
20
25
  }
21
- implementation.initialize(apiKey: apiKey) { success, error in
26
+
27
+ implementation.initialize(apiKey: resolvedKey) { success, error in
22
28
  if let error = error {
23
29
  call.reject(error)
24
30
  } else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-google-navigation",
3
- "version": "0.0.8",
3
+ "version": "0.1.0",
4
4
  "description": "Google maps turn by turn navigation for capcitor",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",