capacitor-google-navigation 0.0.4 → 0.0.6
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/android/src/main/java/com/attributeai/navigation/GoogleNavigation.java +4 -0
- package/android/src/main/java/com/attributeai/navigation/NavigationFragment.java +42 -1
- package/ios/Sources/GoogleNavigationPlugin/GoogleNavigation.swift +14 -1
- package/ios/Sources/GoogleNavigationPlugin/NavigationViewController.swift +12 -8
- package/package.json +1 -1
|
@@ -118,6 +118,10 @@ public class GoogleNavigation {
|
|
|
118
118
|
}
|
|
119
119
|
|
|
120
120
|
NavigationFragment fragment = NavigationFragment.newInstance();
|
|
121
|
+
fragment.setOnCloseListener(() -> {
|
|
122
|
+
fm.beginTransaction().remove(fragment).commitAllowingStateLoss();
|
|
123
|
+
plugin.fireEvent("onNavigationClosed", new JSObject());
|
|
124
|
+
});
|
|
121
125
|
fm.beginTransaction()
|
|
122
126
|
.add(android.R.id.content, fragment, FRAGMENT_TAG)
|
|
123
127
|
.commitAllowingStateLoss();
|
|
@@ -1,9 +1,15 @@
|
|
|
1
1
|
package com.attributeai.navigation;
|
|
2
2
|
|
|
3
|
+
import android.graphics.Color;
|
|
4
|
+
import android.graphics.Typeface;
|
|
3
5
|
import android.os.Bundle;
|
|
6
|
+
import android.util.TypedValue;
|
|
7
|
+
import android.view.Gravity;
|
|
4
8
|
import android.view.LayoutInflater;
|
|
5
9
|
import android.view.View;
|
|
6
10
|
import android.view.ViewGroup;
|
|
11
|
+
import android.widget.Button;
|
|
12
|
+
import android.widget.FrameLayout;
|
|
7
13
|
|
|
8
14
|
import androidx.annotation.NonNull;
|
|
9
15
|
import androidx.annotation.Nullable;
|
|
@@ -19,11 +25,16 @@ import com.google.android.libraries.navigation.NavigationView;
|
|
|
19
25
|
public class NavigationFragment extends Fragment {
|
|
20
26
|
|
|
21
27
|
private NavigationView navigationView;
|
|
28
|
+
private Runnable onCloseListener;
|
|
22
29
|
|
|
23
30
|
public static NavigationFragment newInstance() {
|
|
24
31
|
return new NavigationFragment();
|
|
25
32
|
}
|
|
26
33
|
|
|
34
|
+
public void setOnCloseListener(Runnable listener) {
|
|
35
|
+
this.onCloseListener = listener;
|
|
36
|
+
}
|
|
37
|
+
|
|
27
38
|
@Nullable
|
|
28
39
|
@Override
|
|
29
40
|
public View onCreateView(
|
|
@@ -33,7 +44,37 @@ public class NavigationFragment extends Fragment {
|
|
|
33
44
|
) {
|
|
34
45
|
navigationView = new NavigationView(requireContext());
|
|
35
46
|
navigationView.onCreate(savedInstanceState);
|
|
36
|
-
|
|
47
|
+
|
|
48
|
+
FrameLayout root = new FrameLayout(requireContext());
|
|
49
|
+
root.addView(navigationView, new FrameLayout.LayoutParams(
|
|
50
|
+
FrameLayout.LayoutParams.MATCH_PARENT,
|
|
51
|
+
FrameLayout.LayoutParams.MATCH_PARENT
|
|
52
|
+
));
|
|
53
|
+
|
|
54
|
+
Button closeButton = new Button(requireContext());
|
|
55
|
+
closeButton.setText("✕");
|
|
56
|
+
closeButton.setTextColor(Color.WHITE);
|
|
57
|
+
closeButton.setTextSize(TypedValue.COMPLEX_UNIT_SP, 16);
|
|
58
|
+
closeButton.setTypeface(null, Typeface.BOLD);
|
|
59
|
+
closeButton.setBackgroundColor(Color.argb(153, 0, 0, 0)); // 60% black
|
|
60
|
+
closeButton.setOnClickListener(v -> {
|
|
61
|
+
if (onCloseListener != null) onCloseListener.run();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
int sizePx = (int) TypedValue.applyDimension(
|
|
65
|
+
TypedValue.COMPLEX_UNIT_DIP, 40, getResources().getDisplayMetrics()
|
|
66
|
+
);
|
|
67
|
+
int marginPx = (int) TypedValue.applyDimension(
|
|
68
|
+
TypedValue.COMPLEX_UNIT_DIP, 16, getResources().getDisplayMetrics()
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
FrameLayout.LayoutParams btnParams = new FrameLayout.LayoutParams(sizePx, sizePx);
|
|
72
|
+
btnParams.gravity = Gravity.TOP | Gravity.START;
|
|
73
|
+
btnParams.topMargin = marginPx;
|
|
74
|
+
btnParams.leftMargin = marginPx;
|
|
75
|
+
root.addView(closeButton, btnParams);
|
|
76
|
+
|
|
77
|
+
return root;
|
|
37
78
|
}
|
|
38
79
|
|
|
39
80
|
@Override
|
|
@@ -15,6 +15,7 @@ import GoogleNavigation
|
|
|
15
15
|
|
|
16
16
|
func initialize(apiKey: String, completion: @escaping (Bool, String?) -> Void) {
|
|
17
17
|
DispatchQueue.main.async {
|
|
18
|
+
print("[GoogleNavigation] provideAPIKey called, key length: \(apiKey.count), prefix: \(String(apiKey.prefix(8)))...")
|
|
18
19
|
GMSServices.provideAPIKey(apiKey)
|
|
19
20
|
completion(true, nil)
|
|
20
21
|
}
|
|
@@ -109,7 +110,19 @@ import GoogleNavigation
|
|
|
109
110
|
self?.mapViewController?.setCameraFollowing()
|
|
110
111
|
completion(true, nil)
|
|
111
112
|
} else {
|
|
112
|
-
|
|
113
|
+
let reason: String
|
|
114
|
+
switch routeStatus {
|
|
115
|
+
case .apiKeyNotAuthorized: reason = "API key not authorized for Navigation SDK"
|
|
116
|
+
case .networkError: reason = "Network error — check internet connection"
|
|
117
|
+
case .noRouteFound: reason = "No route found to destination"
|
|
118
|
+
case .locationUnavailable: reason = "Location unavailable — check permissions"
|
|
119
|
+
case .quotaExceeded: reason = "API quota exceeded"
|
|
120
|
+
case .waypointError: reason = "Invalid waypoint coordinates"
|
|
121
|
+
case .travelModeUnsupported: reason = "Travel mode not supported"
|
|
122
|
+
case .canceled: reason = "Route request was canceled"
|
|
123
|
+
default: reason = "Unknown error (code \(routeStatus.rawValue))"
|
|
124
|
+
}
|
|
125
|
+
completion(false, "Route calculation failed: \(reason)")
|
|
113
126
|
}
|
|
114
127
|
}
|
|
115
128
|
}
|
|
@@ -16,18 +16,22 @@ class NavigationMapViewController: UIViewController {
|
|
|
16
16
|
fatalError("init(coder:) not supported")
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
override func
|
|
20
|
-
super.viewDidLoad()
|
|
21
|
-
|
|
19
|
+
override func loadView() {
|
|
22
20
|
let options = GMSMapViewOptions()
|
|
23
|
-
options.frame =
|
|
21
|
+
options.frame = UIScreen.main.bounds
|
|
24
22
|
let mapView = GMSMapView(options: options)
|
|
25
|
-
mapView.autoresizingMask = [.flexibleWidth, .flexibleHeight]
|
|
26
|
-
view.addSubview(mapView)
|
|
27
23
|
self.mapView = mapView
|
|
24
|
+
self.view = mapView
|
|
25
|
+
}
|
|
28
26
|
|
|
29
|
-
|
|
30
|
-
|
|
27
|
+
override func viewDidLoad() {
|
|
28
|
+
super.viewDidLoad()
|
|
29
|
+
|
|
30
|
+
guard let mapView = mapView else { return }
|
|
31
|
+
let enabled = mapView.enableNavigation(with: session)
|
|
32
|
+
if enabled {
|
|
33
|
+
mapView.cameraMode = .following
|
|
34
|
+
}
|
|
31
35
|
|
|
32
36
|
addCloseButton()
|
|
33
37
|
}
|