From 3345df12bce049f96702b679dbc2b0b7f6bbac90 Mon Sep 17 00:00:00 2001 From: funkyfourier Date: Fri, 6 Mar 2020 18:53:40 +0100 Subject: [PATCH] Fixed fused location source (#3320) * Fixed fused location source * Update build.gradle Co-authored-by: Christopher Dro --- lib/android/build.gradle | 5 +++-- .../airbnb/android/react/maps/AirMapView.java | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/lib/android/build.gradle b/lib/android/build.gradle index 3995544f9..893ff2c30 100644 --- a/lib/android/build.gradle +++ b/lib/android/build.gradle @@ -24,7 +24,8 @@ dependencies { implementation('com.facebook.react:react-native:+') { exclude group: 'com.android.support' } - implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '16.1.0')}" - implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '16.1.0')}" + implementation "com.google.android.gms:play-services-base:${safeExtGet('playServicesVersion', '17.0.0')}" + implementation "com.google.android.gms:play-services-maps:${safeExtGet('playServicesVersion', '17.0.0')}" + implementation "com.google.android.gms:play-services-location:17.0.0" implementation 'com.google.maps.android:android-maps-utils:0.5' } diff --git a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java index 332d60f55..424eb149e 100644 --- a/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java +++ b/lib/android/src/main/java/com/airbnb/android/react/maps/AirMapView.java @@ -112,6 +112,7 @@ public class AirMapView extends MapView implements GoogleMap.InfoWindowAdapter, private boolean destroyed = false; private final ThemedReactContext context; private final EventDispatcher eventDispatcher; + private FusedLocationSource fusedLocationSource; private ViewAttacherGroup attacherGroup; @@ -161,6 +162,8 @@ public AirMapView(ThemedReactContext reactContext, ReactApplicationContext appCo final AirMapView view = this; + fusedLocationSource = new FusedLocationSource(context); + gestureDetector = new GestureDetectorCompat(reactContext, new GestureDetector.SimpleOnGestureListener() { @@ -385,6 +388,7 @@ public void onHostResume() { if (hasPermissions()) { //noinspection MissingPermission map.setMyLocationEnabled(showUserLocation); + map.setLocationSource(fusedLocationSource); } synchronized (AirMapView.this) { if (!destroyed) { @@ -513,11 +517,24 @@ public void setCamera(ReadableMap camera) { public void setShowsUserLocation(boolean showUserLocation) { this.showUserLocation = showUserLocation; // hold onto this for lifecycle handling if (hasPermissions()) { + map.setLocationSource(fusedLocationSource); //noinspection MissingPermission map.setMyLocationEnabled(showUserLocation); } } + public void setUserLocationPriority(int priority){ + fusedLocationSource.setPriority(priority); + } + + public void setUserLocationUpdateInterval(int interval){ + fusedLocationSource.setInterval(interval); + } + + public void setUserLocationFastestInterval(int interval){ + fusedLocationSource.setFastestInterval(interval); + } + public void setShowsMyLocationButton(boolean showMyLocationButton) { if (hasPermissions() || !showMyLocationButton) { map.getUiSettings().setMyLocationButtonEnabled(showMyLocationButton);