capacitor-google-navigation 0.1.2 → 0.1.4
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/build.gradle
CHANGED
|
@@ -52,9 +52,8 @@ dependencies {
|
|
|
52
52
|
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
|
53
53
|
implementation project(':capacitor-android')
|
|
54
54
|
implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
|
|
55
|
-
implementation
|
|
56
|
-
|
|
57
|
-
}
|
|
55
|
+
implementation 'com.google.android.libraries.navigation:navigation:7.3.0'
|
|
56
|
+
implementation 'com.google.android.gms:play-services-maps:20.0.0'
|
|
58
57
|
testImplementation "junit:junit:$junitVersion"
|
|
59
58
|
androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
|
|
60
59
|
androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
|
|
@@ -7,11 +7,14 @@ import androidx.fragment.app.FragmentManager;
|
|
|
7
7
|
|
|
8
8
|
import com.getcapacitor.JSObject;
|
|
9
9
|
import com.getcapacitor.Logger;
|
|
10
|
+
import com.google.android.libraries.navigation.ArrivalEvent;
|
|
10
11
|
import com.google.android.libraries.navigation.NavigationApi;
|
|
11
12
|
import com.google.android.libraries.navigation.Navigator;
|
|
12
|
-
import com.google.android.libraries.navigation.RoutingOptions;
|
|
13
13
|
import com.google.android.libraries.navigation.Waypoint;
|
|
14
14
|
|
|
15
|
+
import java.util.ArrayList;
|
|
16
|
+
import java.util.List;
|
|
17
|
+
|
|
15
18
|
public class GoogleNavigation {
|
|
16
19
|
|
|
17
20
|
interface Callback {
|
|
@@ -64,17 +67,10 @@ public class GoogleNavigation {
|
|
|
64
67
|
.setTitle("Destination")
|
|
65
68
|
.build();
|
|
66
69
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
case "WALKING": mode = RoutingOptions.TravelMode.WALKING; break;
|
|
70
|
-
case "CYCLING": mode = RoutingOptions.TravelMode.CYCLING; break;
|
|
71
|
-
case "TWO_WHEELER": mode = RoutingOptions.TravelMode.TWO_WHEELER; break;
|
|
72
|
-
default: mode = RoutingOptions.TravelMode.DRIVING; break;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
RoutingOptions routingOptions = new RoutingOptions().travelMode(mode);
|
|
70
|
+
List<Waypoint> destinations = new ArrayList<>();
|
|
71
|
+
destinations.add(destination);
|
|
76
72
|
|
|
77
|
-
navigator.
|
|
73
|
+
navigator.setDestinations(destinations)
|
|
78
74
|
.setOnResultListener(status -> {
|
|
79
75
|
if (status == Navigator.RouteStatus.OK) {
|
|
80
76
|
navigator.startGuidance();
|
|
@@ -129,17 +125,23 @@ public class GoogleNavigation {
|
|
|
129
125
|
private void attachListeners() {
|
|
130
126
|
if (navigator == null) return;
|
|
131
127
|
|
|
132
|
-
navigator.addArrivalListener(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
128
|
+
navigator.addArrivalListener(new Navigator.ArrivalListener() {
|
|
129
|
+
@Override
|
|
130
|
+
public void onArrival(ArrivalEvent arrivalEvent) {
|
|
131
|
+
Waypoint wp = arrivalEvent.getWaypoint();
|
|
132
|
+
JSObject data = new JSObject();
|
|
133
|
+
data.put("latitude", wp.getPosition().latitude);
|
|
134
|
+
data.put("longitude", wp.getPosition().longitude);
|
|
135
|
+
data.put("title", wp.getTitle());
|
|
136
|
+
plugin.fireEvent("onArrival", data);
|
|
137
|
+
}
|
|
139
138
|
});
|
|
140
139
|
|
|
141
|
-
navigator.addRouteChangedListener(()
|
|
142
|
-
|
|
140
|
+
navigator.addRouteChangedListener(new Navigator.RouteChangedListener() {
|
|
141
|
+
@Override
|
|
142
|
+
public void onRouteChanged() {
|
|
143
|
+
plugin.fireEvent("onRouteChanged", new JSObject());
|
|
144
|
+
}
|
|
143
145
|
});
|
|
144
146
|
}
|
|
145
147
|
}
|