Skip to content

Commit

Permalink
Fixed fused location source (react-native-maps#3320)
Browse files Browse the repository at this point in the history
* Fixed fused location source

* Update build.gradle

Co-authored-by: Christopher Dro <hello@blick-labs.com>
  • Loading branch information
funkyfourier and christopherdro committed Mar 6, 2020
1 parent a7b8517 commit 3345df1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
5 changes: 3 additions & 2 deletions lib/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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() {

Expand Down Expand Up @@ -385,6 +388,7 @@ public void onHostResume() {
if (hasPermissions()) {
//noinspection MissingPermission
map.setMyLocationEnabled(showUserLocation);
map.setLocationSource(fusedLocationSource);
}
synchronized (AirMapView.this) {
if (!destroyed) {
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 3345df1

Please sign in to comment.