capacitor-google-navigation 0.0.1 → 0.0.3
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
|
@@ -64,7 +64,8 @@ The iOS SDK requires the key to be provided before any map or navigator is creat
|
|
|
64
64
|
```swift
|
|
65
65
|
import UIKit
|
|
66
66
|
import Capacitor
|
|
67
|
-
import
|
|
67
|
+
import CapacitorGoogleNavigation
|
|
68
|
+
import GoogleNavigation // required for GMSServices
|
|
68
69
|
|
|
69
70
|
@UIApplicationMain
|
|
70
71
|
class AppDelegate: UIResponder, UIApplicationDelegate {
|
|
@@ -479,6 +480,17 @@ Add both `NSLocationWhenInUseUsageDescription` and `NSLocationAlwaysAndWhenInUse
|
|
|
479
480
|
**CocoaPods not found / pod install fails**
|
|
480
481
|
Make sure CocoaPods is installed (`sudo gem install cocoapods`) and run `npx cap sync` before `pod install`.
|
|
481
482
|
|
|
483
|
+
**iOS — `cap sync` fails with "transitive dependencies that include statically linked binaries"**
|
|
484
|
+
The GoogleNavigation SDK is distributed as a static XCFramework, which conflicts with the default dynamic `use_frameworks!` directive. In your app's `ios/App/Podfile`, change:
|
|
485
|
+
```ruby
|
|
486
|
+
use_frameworks!
|
|
487
|
+
```
|
|
488
|
+
to:
|
|
489
|
+
```ruby
|
|
490
|
+
use_frameworks! :linkage => :static
|
|
491
|
+
```
|
|
492
|
+
Then re-run `pod install` and `npx cap sync`.
|
|
493
|
+
|
|
482
494
|
---
|
|
483
495
|
|
|
484
496
|
## License
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import GoogleMaps
|
|
2
4
|
import GoogleNavigation
|
|
3
5
|
|
|
4
6
|
@objc public class GoogleNavigation: NSObject {
|
|
5
7
|
private weak var plugin: CAPPlugin?
|
|
6
|
-
private var
|
|
7
|
-
private var
|
|
8
|
+
private var mapViewController: NavigationMapViewController?
|
|
9
|
+
private var navigationSession: GMSNavigationSession?
|
|
8
10
|
|
|
9
11
|
init(plugin: CAPPlugin) {
|
|
10
12
|
self.plugin = plugin
|
|
@@ -27,23 +29,45 @@ import GoogleNavigation
|
|
|
27
29
|
return
|
|
28
30
|
}
|
|
29
31
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
32
|
+
DispatchQueue.main.async {
|
|
33
|
+
let options = GMSNavigationTermsAndConditionsOptions(companyName: "App")
|
|
34
|
+
GMSNavigationServices.showTermsAndConditionsDialogIfNeeded(with: options) { [weak self] termsAccepted in
|
|
35
|
+
guard let self = self else { return }
|
|
36
|
+
guard termsAccepted else {
|
|
37
|
+
completion(false, "Navigation terms and conditions not accepted")
|
|
38
|
+
return
|
|
39
|
+
}
|
|
35
40
|
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
41
|
+
guard let session = GMSNavigationServices.createNavigationSession() else {
|
|
42
|
+
completion(false, "Failed to create navigation session")
|
|
43
|
+
return
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
session.isStarted = true
|
|
47
|
+
self.navigationSession = session
|
|
48
|
+
session.navigator?.add(self)
|
|
49
|
+
|
|
50
|
+
let mapVC = NavigationMapViewController(session: session)
|
|
51
|
+
mapVC.modalPresentationStyle = .fullScreen
|
|
52
|
+
self.mapViewController = mapVC
|
|
53
|
+
|
|
54
|
+
presentingVC.present(mapVC, animated: true) {
|
|
55
|
+
self.plugin?.notifyListeners("onNavigationReady", data: [:])
|
|
56
|
+
completion(true, nil)
|
|
57
|
+
}
|
|
58
|
+
}
|
|
39
59
|
}
|
|
40
60
|
}
|
|
41
61
|
|
|
42
62
|
func dismissNavigationViewController(completion: @escaping () -> Void) {
|
|
43
|
-
|
|
44
|
-
self.
|
|
45
|
-
|
|
46
|
-
|
|
63
|
+
DispatchQueue.main.async {
|
|
64
|
+
self.mapViewController?.dismiss(animated: true) {
|
|
65
|
+
self.navigationSession?.navigator?.remove(self)
|
|
66
|
+
self.navigationSession?.isStarted = false
|
|
67
|
+
self.navigationSession = nil
|
|
68
|
+
self.mapViewController = nil
|
|
69
|
+
completion()
|
|
70
|
+
}
|
|
47
71
|
}
|
|
48
72
|
}
|
|
49
73
|
|
|
@@ -53,7 +77,7 @@ import GoogleNavigation
|
|
|
53
77
|
travelMode: String,
|
|
54
78
|
completion: @escaping (Bool, String?) -> Void
|
|
55
79
|
) {
|
|
56
|
-
guard let navigator =
|
|
80
|
+
guard let session = navigationSession, let navigator = session.navigator else {
|
|
57
81
|
completion(false, "Navigation view must be shown before starting navigation")
|
|
58
82
|
return
|
|
59
83
|
}
|
|
@@ -64,19 +88,17 @@ import GoogleNavigation
|
|
|
64
88
|
return
|
|
65
89
|
}
|
|
66
90
|
|
|
67
|
-
let mode: GMSNavigationTravelMode
|
|
68
91
|
switch travelMode {
|
|
69
|
-
case "WALKING":
|
|
70
|
-
case "CYCLING":
|
|
71
|
-
case "TWO_WHEELER":
|
|
72
|
-
default:
|
|
92
|
+
case "WALKING": session.travelMode = .walking
|
|
93
|
+
case "CYCLING": session.travelMode = .cycling
|
|
94
|
+
case "TWO_WHEELER": session.travelMode = .twoWheeler
|
|
95
|
+
default: session.travelMode = .driving
|
|
73
96
|
}
|
|
74
|
-
navViewController?.mapView.travelMode = mode
|
|
75
97
|
|
|
76
|
-
navigator.setDestinations([waypoint]) { routeStatus in
|
|
98
|
+
navigator.setDestinations([waypoint]) { [weak self] routeStatus in
|
|
77
99
|
if routeStatus == .OK {
|
|
78
100
|
navigator.isGuidanceActive = true
|
|
79
|
-
self
|
|
101
|
+
self?.mapViewController?.setCameraFollowing()
|
|
80
102
|
completion(true, nil)
|
|
81
103
|
} else {
|
|
82
104
|
completion(false, "Route calculation failed: \(routeStatus.rawValue)")
|
|
@@ -85,16 +107,13 @@ import GoogleNavigation
|
|
|
85
107
|
}
|
|
86
108
|
|
|
87
109
|
func stopNavigation() {
|
|
88
|
-
navigator?.isGuidanceActive = false
|
|
89
|
-
navigator?.clearDestinations()
|
|
110
|
+
navigationSession?.navigator?.isGuidanceActive = false
|
|
111
|
+
navigationSession?.navigator?.clearDestinations()
|
|
90
112
|
}
|
|
91
113
|
}
|
|
92
114
|
|
|
93
|
-
extension GoogleNavigation:
|
|
94
|
-
public func
|
|
95
|
-
_ navigationViewController: GMSNavigationViewController,
|
|
96
|
-
didArriveAtWaypoint waypoint: GMSNavigationWaypoint
|
|
97
|
-
) {
|
|
115
|
+
extension GoogleNavigation: GMSNavigatorListener {
|
|
116
|
+
public func navigator(_ navigator: GMSNavigator, didArriveAt waypoint: GMSNavigationWaypoint) {
|
|
98
117
|
plugin?.notifyListeners("onArrival", data: [
|
|
99
118
|
"latitude": waypoint.coordinate.latitude,
|
|
100
119
|
"longitude": waypoint.coordinate.longitude,
|
|
@@ -102,9 +121,7 @@ extension GoogleNavigation: GMSNavigationViewControllerDelegate {
|
|
|
102
121
|
])
|
|
103
122
|
}
|
|
104
123
|
|
|
105
|
-
public func
|
|
106
|
-
_ navigationViewController: GMSNavigationViewController
|
|
107
|
-
) {
|
|
124
|
+
public func navigatorDidChangeRoute(_ navigator: GMSNavigator) {
|
|
108
125
|
plugin?.notifyListeners("onRouteChanged", data: [:])
|
|
109
126
|
}
|
|
110
127
|
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import UIKit
|
|
2
|
+
import GoogleMaps
|
|
3
|
+
import GoogleNavigation
|
|
4
|
+
|
|
5
|
+
class NavigationMapViewController: UIViewController {
|
|
6
|
+
private let session: GMSNavigationSession
|
|
7
|
+
private var mapView: GMSMapView?
|
|
8
|
+
|
|
9
|
+
init(session: GMSNavigationSession) {
|
|
10
|
+
self.session = session
|
|
11
|
+
super.init(nibName: nil, bundle: nil)
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
required init?(coder: NSCoder) {
|
|
15
|
+
fatalError("init(coder:) not supported")
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
override func viewDidLoad() {
|
|
19
|
+
super.viewDidLoad()
|
|
20
|
+
|
|
21
|
+
let options = GMSMapViewOptions()
|
|
22
|
+
options.frame = view.bounds
|
|
23
|
+
let mapView = GMSMapView(options: options)
|
|
24
|
+
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
25
|
+
view.addSubview(mapView)
|
|
26
|
+
self.mapView = mapView
|
|
27
|
+
|
|
28
|
+
_ = mapView.enableNavigation(with: session)
|
|
29
|
+
mapView.cameraMode = .following
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
func setCameraFollowing() {
|
|
33
|
+
mapView?.cameraMode = .following
|
|
34
|
+
}
|
|
35
|
+
}
|