capacitor-google-navigation 0.1.2 → 0.1.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/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"
|
|
@@ -9,9 +9,11 @@ import com.getcapacitor.JSObject;
|
|
|
9
9
|
import com.getcapacitor.Logger;
|
|
10
10
|
import com.google.android.libraries.navigation.NavigationApi;
|
|
11
11
|
import com.google.android.libraries.navigation.Navigator;
|
|
12
|
-
import com.google.android.libraries.navigation.RoutingOptions;
|
|
13
12
|
import com.google.android.libraries.navigation.Waypoint;
|
|
14
13
|
|
|
14
|
+
import java.util.ArrayList;
|
|
15
|
+
import java.util.List;
|
|
16
|
+
|
|
15
17
|
public class GoogleNavigation {
|
|
16
18
|
|
|
17
19
|
interface Callback {
|
|
@@ -59,30 +61,25 @@ public class GoogleNavigation {
|
|
|
59
61
|
return;
|
|
60
62
|
}
|
|
61
63
|
|
|
62
|
-
Waypoint destination =
|
|
64
|
+
Waypoint destination = Waypoint.builder()
|
|
63
65
|
.setLatLng(lat, lng)
|
|
64
66
|
.setTitle("Destination")
|
|
65
67
|
.build();
|
|
66
68
|
|
|
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);
|
|
69
|
+
List<Waypoint> destinations = new ArrayList<>();
|
|
70
|
+
destinations.add(destination);
|
|
76
71
|
|
|
77
|
-
navigator.
|
|
78
|
-
|
|
72
|
+
navigator.setDestinations(destinations, new Navigator.RouteStatusListener() {
|
|
73
|
+
@Override
|
|
74
|
+
public void onRouteStatusResult(Navigator.RouteStatus status) {
|
|
79
75
|
if (status == Navigator.RouteStatus.OK) {
|
|
80
76
|
navigator.startGuidance();
|
|
81
77
|
callback.onResult(true, null);
|
|
82
78
|
} else {
|
|
83
79
|
callback.onResult(false, "Route error: " + status.name());
|
|
84
80
|
}
|
|
85
|
-
}
|
|
81
|
+
}
|
|
82
|
+
});
|
|
86
83
|
}
|
|
87
84
|
|
|
88
85
|
public void stopNavigation() {
|
|
@@ -129,17 +126,23 @@ public class GoogleNavigation {
|
|
|
129
126
|
private void attachListeners() {
|
|
130
127
|
if (navigator == null) return;
|
|
131
128
|
|
|
132
|
-
navigator.addArrivalListener(
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
129
|
+
navigator.addArrivalListener(new Navigator.ArrivalListener() {
|
|
130
|
+
@Override
|
|
131
|
+
public void onArrival(Navigator.ArrivalEvent arrivalEvent) {
|
|
132
|
+
Waypoint wp = arrivalEvent.getWaypoint();
|
|
133
|
+
JSObject data = new JSObject();
|
|
134
|
+
data.put("latitude", wp.getPosition().latitude);
|
|
135
|
+
data.put("longitude", wp.getPosition().longitude);
|
|
136
|
+
data.put("title", wp.getTitle());
|
|
137
|
+
plugin.fireEvent("onArrival", data);
|
|
138
|
+
}
|
|
139
139
|
});
|
|
140
140
|
|
|
141
|
-
navigator.addRouteChangedListener(()
|
|
142
|
-
|
|
141
|
+
navigator.addRouteChangedListener(new Navigator.RouteChangedListener() {
|
|
142
|
+
@Override
|
|
143
|
+
public void onRouteChanged() {
|
|
144
|
+
plugin.fireEvent("onRouteChanged", new JSObject());
|
|
145
|
+
}
|
|
143
146
|
});
|
|
144
147
|
}
|
|
145
148
|
}
|