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..4d759030 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 @@ -636,11 +636,16 @@ class CapacitorGoogleMap( } @SuppressLint("MissingPermission") - fun enableCurrentLocation(enabled: Boolean, callback: (error: GoogleMapsError?) -> Unit) { + fun enableCurrentLocation( + showLocationDot: Boolean, + showMyLocationButton: Boolean, + callback: (error: GoogleMapsError?) -> Unit + ) { try { googleMap ?: throw GoogleMapNotAvailable() CoroutineScope(Dispatchers.Main).launch { - googleMap?.isMyLocationEnabled = enabled + googleMap?.isMyLocationEnabled = showLocationDot + googleMap?.uiSettings?.isMyLocationButtonEnabled = showMyLocationButton callback(null) } } catch (e: GoogleMapsError) { @@ -648,6 +653,7 @@ class CapacitorGoogleMap( } } + fun setPadding(padding: GoogleMapPadding, callback: (error: GoogleMapsError?) -> Unit) { try { googleMap ?: throw GoogleMapNotAvailable() 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..f07f469f 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 @@ -763,14 +763,34 @@ class CapacitorGoogleMapsPlugin : Plugin(), OnMapsSdkInitializedCallback { } @PluginMethod - fun enableCurrentLocation(call: PluginCall) { - if (getPermissionState(LOCATION) != PermissionState.GRANTED) { - requestAllPermissions(call, "enableCurrentLocationCallback") - } else { - internalEnableCurrentLocation(call) + @SuppressLint("MissingPermission") + fun internalEnableCurrentLocation(call: PluginCall) { + val id = call.getString("id") + val enabled = call.getBoolean("enabled") ?: false + val showButton = call.getBoolean("showButton") ?: false + + if (id == null) { + call.reject("ID is required") + return + } + + val map = maps[id] + if (map == null) { + call.reject("Map not found") + return + } + + map.enableCurrentLocation(enabled) { error -> + if (error != null) { + call.reject("Error enabling location", error.localizedMessage) + } else { + map.setMyLocationButtonEnabled(showButton) + call.resolve() + } } } + @PermissionCallback fun enableCurrentLocationCallback(call: PluginCall) { if (getPermissionState(LOCATION) == PermissionState.GRANTED) { diff --git a/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift b/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift index 3d2a32a5..86f2edf7 100644 --- a/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift +++ b/plugin/ios/Plugin/CapacitorGoogleMapsPlugin.swift @@ -669,7 +669,7 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate { handleError(call, error: error) } } - + @objc func enableCurrentLocation(_ call: CAPPluginCall) { do { guard let id = call.getString("id") else { @@ -684,13 +684,16 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate { throw GoogleMapErrors.invalidArguments("enabled is missing") } + let showButton = call.getBool("showButton") ?? false + let locationStatus = checkLocationPermission() - if enabled && !(locationStatus == "granted" || locationStatus == "prompt") { + if enabled && !(locationStatus == "granted" || locationStatus == "prompt") { throw GoogleMapErrors.permissionsDeniedLocation } try map.enableCurrentLocation(enabled: enabled) + map.setMyLocationButtonEnabled(enabled: showButton) call.resolve() } catch { @@ -698,6 +701,7 @@ public class CapacitorGoogleMapsPlugin: CAPPlugin, GMSMapViewDelegate { } } + @objc func enableClustering(_ call: CAPPluginCall) { do { guard let id = call.getString("id") else { diff --git a/plugin/ios/Plugin/Map.swift b/plugin/ios/Plugin/Map.swift index 71e4a7de..dfb7fd5e 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, showButton: Bool) throws { DispatchQueue.main.sync { self.mapViewController.GMapView.isMyLocationEnabled = enabled + self.mapViewController.GMapView.settings.myLocationButton = showButton } } diff --git a/plugin/src/implementation.ts b/plugin/src/implementation.ts index a7ff4535..1ea66444 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; + showButton?: boolean; } export interface AddMarkersArgs { id: string;