diff --git a/README.md b/README.md index 0d858c28..483481d9 100644 --- a/README.md +++ b/README.md @@ -617,12 +617,13 @@ enableAccessibilityElements(enabled: boolean) => Promise ### enableCurrentLocation(...) ```typescript -enableCurrentLocation(enabled: boolean) => Promise +enableCurrentLocation(enabled: boolean, options: EnableCurrentLocationOptions) => Promise ``` -| Param | Type | -| ------------- | -------------------- | -| **`enabled`** | boolean | +| Param | Type | +| ------------- | ------------------------------------------------------------------------------------- | +| **`enabled`** | boolean | +| **`options`** | EnableCurrentLocationOptions | -------------------- @@ -1030,6 +1031,13 @@ Configuration properties for a Google Map Camera | **`animationDuration`** | number | This configuration option is not being used. | | +#### EnableCurrentLocationOptions + +| Prop | Type | +| ------------------ | -------------------- | +| **`enableButton`** | boolean | + + #### MapPadding Controls for setting padding on the 'visible' region of the view. diff --git a/plugin/README.md b/plugin/README.md index e278abdf..a826ac24 100644 --- a/plugin/README.md +++ b/plugin/README.md @@ -618,12 +618,13 @@ enableAccessibilityElements(enabled: boolean) => Promise ### enableCurrentLocation(...) ```typescript -enableCurrentLocation(enabled: boolean) => Promise +enableCurrentLocation(enabled: boolean, options: EnableCurrentLocationOptions) => Promise ``` -| Param | Type | -| ------------- | -------------------- | -| **`enabled`** | boolean | +| Param | Type | +| ------------- | ------------------------------------------------------------------------------------- | +| **`enabled`** | boolean | +| **`options`** | EnableCurrentLocationOptions | -------------------- @@ -1044,6 +1045,13 @@ Configuration properties for a Google Map Camera | **`animationDuration`** | number | This configuration option is not being used. | | +#### EnableCurrentLocationOptions + +| Prop | Type | +| ------------------ | -------------------- | +| **`enableButton`** | boolean | + + #### MapPadding Controls for setting padding on the 'visible' region of the view. diff --git a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt index a22aa220..6d0f9750 100644 --- a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt +++ b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMap.kt @@ -45,7 +45,7 @@ class CapacitorGoogleMap( private val markers = HashMap() private val polygons = HashMap() private val circles = HashMap() - private val polylines = HashMap() + private val polylines = HashMap() private val markerIcons = HashMap() private var clusterManager: ClusterManager? = null @@ -310,7 +310,7 @@ class CapacitorGoogleMap( } val googleMapPolyline = googleMap?.addPolyline(polylineOptions.await()) googleMapPolyline?.tag = it.tag - + it.googleMapsPolyline = googleMapPolyline polylines[googleMapPolyline!!.id] = it @@ -636,11 +636,12 @@ class CapacitorGoogleMap( } @SuppressLint("MissingPermission") - fun enableCurrentLocation(enabled: Boolean, callback: (error: GoogleMapsError?) -> Unit) { + fun enableCurrentLocation(enabled: Boolean, enableButton: Boolean, callback: (error: GoogleMapsError?) -> Unit) { try { googleMap ?: throw GoogleMapNotAvailable() CoroutineScope(Dispatchers.Main).launch { googleMap?.isMyLocationEnabled = enabled + googleMap?.uiSettings?.isMyLocationButtonEnabled = enableButton callback(null) } } catch (e: GoogleMapsError) { @@ -739,7 +740,7 @@ class CapacitorGoogleMap( return polygonOptions } - + private fun buildPolyline(line: CapacitorGoogleMapPolyline): PolylineOptions { val polylineOptions = PolylineOptions() polylineOptions.width(line.strokeWidth * this.config.devicePixelRatio) diff --git a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt index 143eca88..8317553c 100644 --- a/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt +++ b/plugin/android/src/main/java/com/capacitorjs/plugins/googlemaps/CapacitorGoogleMapsPlugin.kt @@ -1017,7 +1017,9 @@ class CapacitorGoogleMapsPlugin : Plugin(), OnMapsSdkInitializedCallback { val enabled = call.getBoolean("enabled") ?: throw InvalidArgumentsError("enabled is missing") - map.enableCurrentLocation(enabled) { err -> + val enableButton = call.getBoolean("enableButton") ?: false + + map.enableCurrentLocation(enabled, enableButton) { err -> if (err != null) { throw err } diff --git a/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift b/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift index 59af66ba..d910dcfb 100644 --- a/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift +++ b/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift @@ -686,8 +686,10 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate { if enabled && checkLocationPermission() != "granted" { throw GoogleMapErrors.permissionsDeniedLocation } + + let enableButton = call.getBool("enableButton") ?? false - try map.enableCurrentLocation(enabled: enabled) + try map.enableCurrentLocation(enabled: enabled, enableButton: enableButton) call.resolve() } catch { diff --git a/plugin/ios/Plugin/Map.swift b/plugin/ios/Plugin/Map.swift index 71e4a7de..c9fc26cd 100644 --- a/plugin/ios/Plugin/Map.swift +++ b/plugin/ios/Plugin/Map.swift @@ -455,9 +455,10 @@ public class Map { } } - func enableCurrentLocation(enabled: Bool) throws { + func enableCurrentLocation(enabled: Bool, enableButton: Bool) throws { DispatchQueue.main.sync { self.mapViewController.GMapView.isMyLocationEnabled = enabled + self.mapViewController.GMapView.settings.myLocationButton = enableButton } } diff --git a/plugin/src/definitions.ts b/plugin/src/definitions.ts index 6fa91254..6e8be65f 100644 --- a/plugin/src/definitions.ts +++ b/plugin/src/definitions.ts @@ -458,6 +458,10 @@ export interface CircleClickCallbackData { tag?: string; } +export interface EnableCurrentLocationOptions { + enableButton?: boolean; +} + export interface MyLocationButtonClickCallbackData { mapId: string; } diff --git a/plugin/src/implementation.ts b/plugin/src/implementation.ts index a7ff4535..96ba3b52 100644 --- a/plugin/src/implementation.ts +++ b/plugin/src/implementation.ts @@ -135,6 +135,7 @@ export interface PaddingArgs { export interface CurrentLocArgs { id: string; enabled: boolean; + enableButton: boolean; } export interface AddMarkersArgs { id: string; diff --git a/plugin/src/map.ts b/plugin/src/map.ts index 977c032c..474af3b7 100644 --- a/plugin/src/map.ts +++ b/plugin/src/map.ts @@ -1,7 +1,7 @@ import { Capacitor } from '@capacitor/core'; import type { PluginListenerHandle } from '@capacitor/core'; -import type { +import { CameraConfig, Marker, MapPadding, @@ -19,6 +19,7 @@ import type { CircleClickCallbackData, Polyline, PolylineCallbackData, + EnableCurrentLocationOptions, } from './definitions'; import { LatLngBounds, MapType } from './definitions'; import type { CreateMapArgs } from './implementation'; @@ -55,7 +56,7 @@ export interface GoogleMapInterface { enableIndoorMaps(enabled: boolean): Promise; enableTrafficLayer(enabled: boolean): Promise; enableAccessibilityElements(enabled: boolean): Promise; - enableCurrentLocation(enabled: boolean): Promise; + enableCurrentLocation(enabled: boolean, options: EnableCurrentLocationOptions): Promise; setPadding(padding: MapPadding): Promise; /** * Get the map's current viewport latitude and longitude bounds. @@ -532,12 +533,14 @@ export class GoogleMap { * Set whether the My Location dot and accuracy circle is enabled. * * @param enabled + * @param options * @returns */ - async enableCurrentLocation(enabled: boolean): Promise { + async enableCurrentLocation(enabled: boolean, options: EnableCurrentLocationOptions = {}): Promise { return CapacitorGoogleMaps.enableCurrentLocation({ id: this.id, enabled, + enableButton: options.enableButton ?? false, }); }