From e1e50e5bb5eb1797a7598a96f0bb8742bcf7a51b Mon Sep 17 00:00:00 2001 From: Andrei Diaconu Date: Sun, 17 Feb 2019 22:00:59 +0200 Subject: [PATCH] Revert "Add a My Location parameter to the Google Maps plugin (#898)" This reverts commit ae8875ddfdf7c24e03b69ce946841833fa731585. --- .../flutter/plugins/googlemaps/Convert.java | 4 --- .../plugins/googlemaps/GoogleMapBuilder.java | 7 ---- .../googlemaps/GoogleMapController.java | 33 ------------------- .../googlemaps/GoogleMapOptionsSink.java | 2 -- .../android/app/src/main/AndroidManifest.xml | 1 - .../example/ios/Runner/Info.plist | 6 ++-- .../example/lib/map_ui.dart | 15 --------- .../ios/Classes/GoogleMapController.h | 1 - .../ios/Classes/GoogleMapController.m | 14 ++------ packages/google_maps_flutter/lib/src/ui.dart | 30 ----------------- 10 files changed, 5 insertions(+), 108 deletions(-) diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java index b9314eb3c87c..f26d675de5de 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/Convert.java @@ -209,10 +209,6 @@ static void interpretGoogleMapOptions(Object o, GoogleMapOptionsSink sink) { if (zoomGesturesEnabled != null) { sink.setZoomGesturesEnabled(toBoolean(zoomGesturesEnabled)); } - final Object myLocationEnabled = data.get("myLocationEnabled"); - if (myLocationEnabled != null) { - sink.setMyLocationEnabled(toBoolean(myLocationEnabled)); - } } static void interpretMarkerOptions(Object o, MarkerOptionsSink sink) { diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java index 64d553327dad..d2b1c6db4e93 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapBuilder.java @@ -14,14 +14,12 @@ class GoogleMapBuilder implements GoogleMapOptionsSink { private final GoogleMapOptions options = new GoogleMapOptions(); private boolean trackCameraPosition = false; - private boolean myLocationEnabled = false; GoogleMapController build( int id, Context context, AtomicInteger state, PluginRegistry.Registrar registrar) { final GoogleMapController controller = new GoogleMapController(id, context, state, registrar, options); controller.init(); - controller.setMyLocationEnabled(myLocationEnabled); controller.setTrackCameraPosition(trackCameraPosition); return controller; } @@ -80,9 +78,4 @@ public void setTiltGesturesEnabled(boolean tiltGesturesEnabled) { public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { options.zoomGesturesEnabled(zoomGesturesEnabled); } - - @Override - public void setMyLocationEnabled(boolean myLocationEnabled) { - this.myLocationEnabled = myLocationEnabled; - } } diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java index 501c660d6b38..eb473af2ac92 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapController.java @@ -11,14 +11,10 @@ import static io.flutter.plugins.googlemaps.GoogleMapsPlugin.STARTED; import static io.flutter.plugins.googlemaps.GoogleMapsPlugin.STOPPED; -import android.Manifest; import android.app.Activity; import android.app.Application; import android.content.Context; -import android.content.pm.PackageManager; import android.os.Bundle; -import android.support.v4.content.ContextCompat; -import android.util.Log; import android.view.View; import com.google.android.gms.maps.CameraUpdate; import com.google.android.gms.maps.CameraUpdateFactory; @@ -52,7 +48,6 @@ final class GoogleMapController OnMapReadyCallback, OnMarkerTappedListener, PlatformView { - private static final String TAG = "GoogleMapController"; private final int id; private final AtomicInteger activityState; private final MethodChannel methodChannel; @@ -61,12 +56,10 @@ final class GoogleMapController private final Map markers; private GoogleMap googleMap; private boolean trackCameraPosition = false; - private boolean myLocationEnabled = false; private boolean disposed = false; private final float density; private MethodChannel.Result mapReadyResult; private final int registrarActivityHashCode; - private final Context context; GoogleMapController( int id, @@ -75,7 +68,6 @@ final class GoogleMapController PluginRegistry.Registrar registrar, GoogleMapOptions options) { this.id = id; - this.context = context; this.activityState = activityState; this.registrar = registrar; this.mapView = new MapView(context, options); @@ -179,7 +171,6 @@ public void onMapReady(GoogleMap googleMap) { googleMap.setOnCameraMoveListener(this); googleMap.setOnCameraIdleListener(this); googleMap.setOnMarkerClickListener(this); - updateMyLocationEnabled(); } @Override @@ -408,28 +399,4 @@ public void setMinMaxZoomPreference(Float min, Float max) { public void setZoomGesturesEnabled(boolean zoomGesturesEnabled) { googleMap.getUiSettings().setZoomGesturesEnabled(zoomGesturesEnabled); } - - @Override - public void setMyLocationEnabled(boolean myLocationEnabled) { - if (this.myLocationEnabled == myLocationEnabled) { - return; - } - this.myLocationEnabled = myLocationEnabled; - if (googleMap != null) { - updateMyLocationEnabled(); - } - } - - private void updateMyLocationEnabled() { - if (ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION) - == PackageManager.PERMISSION_GRANTED - || ContextCompat.checkSelfPermission(context, Manifest.permission.ACCESS_COARSE_LOCATION) - == PackageManager.PERMISSION_GRANTED) { - googleMap.setMyLocationEnabled(myLocationEnabled); - } else { - // TODO(amirh): Make the options update fail. - // https://github.com/flutter/flutter/issues/24327 - Log.e(TAG, "Cannot enable MyLocation layer as location permissions are not granted"); - } - } } diff --git a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java index 03b67aa55ebc..80607ded7f2a 100644 --- a/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java +++ b/packages/google_maps_flutter/android/src/main/java/io/flutter/plugins/googlemaps/GoogleMapOptionsSink.java @@ -28,6 +28,4 @@ interface GoogleMapOptionsSink { void setTrackCameraPosition(boolean trackCameraPosition); void setZoomGesturesEnabled(boolean zoomGesturesEnabled); - - void setMyLocationEnabled(boolean myLocationEnabled); } diff --git a/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml b/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml index 01a15d7dc18f..510522039296 100644 --- a/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml +++ b/packages/google_maps_flutter/example/android/app/src/main/AndroidManifest.xml @@ -2,7 +2,6 @@ package="io.flutter.plugins.googlemapsexample"> - 1 LSRequiresIPhoneOS - NSLocationWhenInUseUsageDescription - This app needs your location to test the location feature of the Google Maps plugin. UILaunchStoryboardName LaunchScreen UIMainStoryboardFile @@ -45,9 +43,9 @@ UIInterfaceOrientationLandscapeLeft UIInterfaceOrientationLandscapeRight - UIViewControllerBasedStatusBarAppearance - io.flutter.embedded_views_preview + UIViewControllerBasedStatusBarAppearance + diff --git a/packages/google_maps_flutter/example/lib/map_ui.dart b/packages/google_maps_flutter/example/lib/map_ui.dart index 589fa2bbbe55..2dcf41fec8fe 100644 --- a/packages/google_maps_flutter/example/lib/map_ui.dart +++ b/packages/google_maps_flutter/example/lib/map_ui.dart @@ -182,20 +182,6 @@ class MapUiBodyState extends State { ); } - Widget _myLocationToggler() { - return FlatButton( - child: Text( - '${_options.myLocationEnabled ? 'disable' : 'enable'} my location'), - onPressed: () { - mapController.updateMapOptions( - GoogleMapOptions( - myLocationEnabled: !_options.myLocationEnabled, - ), - ); - }, - ); - } - @override Widget build(BuildContext context) { final List columnChildren = [ @@ -240,7 +226,6 @@ class MapUiBodyState extends State { _scrollToggler(), _tiltToggler(), _zoomToggler(), - _myLocationToggler(), ], ), ), diff --git a/packages/google_maps_flutter/ios/Classes/GoogleMapController.h b/packages/google_maps_flutter/ios/Classes/GoogleMapController.h index e8252a743f44..eecc69c14cc6 100644 --- a/packages/google_maps_flutter/ios/Classes/GoogleMapController.h +++ b/packages/google_maps_flutter/ios/Classes/GoogleMapController.h @@ -27,7 +27,6 @@ - (void)setTiltGesturesEnabled:(BOOL)enabled; - (void)setTrackCameraPosition:(BOOL)enabled; - (void)setZoomGesturesEnabled:(BOOL)enabled; -- (void)setMyLocationEnabled:(BOOL)enabled; @end // Defines map overlay controllable from Flutter. diff --git a/packages/google_maps_flutter/ios/Classes/GoogleMapController.m b/packages/google_maps_flutter/ios/Classes/GoogleMapController.m index c1225f14bebf..652760ae5567 100644 --- a/packages/google_maps_flutter/ios/Classes/GoogleMapController.m +++ b/packages/google_maps_flutter/ios/Classes/GoogleMapController.m @@ -60,11 +60,12 @@ - (instancetype)initWithFrame:(CGRect)frame if ([super init]) { _viewId = viewId; - GMSCameraPosition* camera = toOptionalCameraPosition(args[@"cameraPosition"]); + NSDictionary* options = args[@"options"]; + GMSCameraPosition* camera = toOptionalCameraPosition(options[@"cameraPosition"]); _mapView = [GMSMapView mapWithFrame:frame camera:camera]; _markers = [NSMutableDictionary dictionaryWithCapacity:1]; _trackCameraPosition = NO; - interpretMapOptions(args, self); + interpretMapOptions(options, self); NSString* channelName = [NSString stringWithFormat:@"plugins.flutter.io/google_maps_%lld", viewId]; _channel = [FlutterMethodChannel methodChannelWithName:channelName @@ -216,11 +217,6 @@ - (void)setZoomGesturesEnabled:(BOOL)enabled { _mapView.settings.zoomGestures = enabled; } -- (void)setMyLocationEnabled:(BOOL)enabled { - _mapView.myLocationEnabled = enabled; - _mapView.settings.myLocationButton = enabled; -} - #pragma mark - GMSMapViewDelegate methods - (void)mapView:(GMSMapView*)mapView willMove:(BOOL)gesture { @@ -399,10 +395,6 @@ static void interpretMapOptions(id json, id sink) { if (zoomGesturesEnabled) { [sink setZoomGesturesEnabled:toBool(zoomGesturesEnabled)]; } - id myLocationEnabled = data[@"myLocationEnabled"]; - if (myLocationEnabled) { - [sink setMyLocationEnabled:toBool(myLocationEnabled)]; - } } static void interpretMarkerOptions(id json, id sink, diff --git a/packages/google_maps_flutter/lib/src/ui.dart b/packages/google_maps_flutter/lib/src/ui.dart index 66cfc60a1c2b..acedb0eb2d88 100644 --- a/packages/google_maps_flutter/lib/src/ui.dart +++ b/packages/google_maps_flutter/lib/src/ui.dart @@ -86,7 +86,6 @@ class GoogleMapOptions { this.tiltGesturesEnabled, this.trackCameraPosition, this.zoomGesturesEnabled, - this.myLocationEnabled, }); /// The desired position of the map camera. @@ -126,31 +125,6 @@ class GoogleMapOptions { /// True if the map view should respond to zoom gestures. final bool zoomGesturesEnabled; - /// True if a "My Location" layer should be shown on the map. - /// - /// This layer includes a location indicator at the current device location, - /// as well as a My Location button. - /// * The indicator is a small blue dot if the device is stationary, or a - /// chevron if the device is moving. - /// * The My Location button animates to focus on the user's current location - /// if the user's location is currently known. - /// - /// Enabling this feature requires adding location permissions to both native - /// platforms of your app. - /// * On Android add either - /// `` - /// or `` - /// to your `AndroidManifest.xml` file. `ACCESS_COARSE_LOCATION` returns a - /// location with an accuracy approximately equivalent to a city block, while - /// `ACCESS_FINE_LOCATION` returns as precise a location as possible, although - /// it consumes more battery power. You will also need to request these - /// permissions during run-time. If they are not granted, the My Location - /// feature will fail silently. - /// * On iOS add a `NSLocationWhenInUseUsageDescription` key to your - /// `Info.plist` file. This will automatically prompt the user for permissions - /// when the map tries to turn on the My Location layer. - final bool myLocationEnabled; - /// Default user interface options. /// /// Specifies a map view that @@ -164,7 +138,6 @@ class GoogleMapOptions { /// * responds to tilt gestures; [tiltGesturesEnabled] is true /// * is silent about camera movement; [trackCameraPosition] is false /// * responds to zoom gestures; [zoomGesturesEnabled] is true - /// * does not show user location; [myLocationEnabled] is false static final GoogleMapOptions defaultOptions = GoogleMapOptions( compassEnabled: true, cameraPosition: const CameraPosition(target: LatLng(0.0, 0.0)), @@ -176,7 +149,6 @@ class GoogleMapOptions { tiltGesturesEnabled: true, trackCameraPosition: false, zoomGesturesEnabled: true, - myLocationEnabled: false, ); /// Creates a new options object whose values are the same as this instance, @@ -200,7 +172,6 @@ class GoogleMapOptions { tiltGesturesEnabled: change.tiltGesturesEnabled ?? tiltGesturesEnabled, trackCameraPosition: change.trackCameraPosition ?? trackCameraPosition, zoomGesturesEnabled: change.zoomGesturesEnabled ?? zoomGesturesEnabled, - myLocationEnabled: change.myLocationEnabled ?? myLocationEnabled, ); } @@ -223,7 +194,6 @@ class GoogleMapOptions { addIfPresent('tiltGesturesEnabled', tiltGesturesEnabled); addIfPresent('trackCameraPosition', trackCameraPosition); addIfPresent('zoomGesturesEnabled', zoomGesturesEnabled); - addIfPresent('myLocationEnabled', myLocationEnabled); return json; } }