Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 5 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ To use certain location features, the SDK requires the following permissions to

This plugin will use the following project variables (defined in your app's `variables.gradle` file):

- `googleMapsPlayServicesVersion`: version of `com.google.android.gms:play-services-maps` (default: `19.2.0`)
- `googleMapsUtilsVersion`: version of `com.google.maps.android:android-maps-utils` (default: `3.19.1`)
- `googleMapsKtxVersion`: version of `com.google.maps.android:maps-ktx` (default: `5.2.1`)
- `googleMapsUtilsKtxVersion`: version of `com.google.maps.android:maps-utils-ktx` (default: `5.2.1`)
- `kotlinxCoroutinesVersion`: version of `org.jetbrains.kotlinx:kotlinx-coroutines-android` and `org.jetbrains.kotlinx:kotlinx-coroutines-core` (default: `1.10.2`)
- `androidxCoreVersion`: version of `androidx.core:core` (default: `1.19.0`)

- `googleMapsPlayServicesVersion`: version of `com.google.android.gms:play-services-maps` (default: `20.0.0`)
- `googleMapsUtilsVersion`: version of `com.google.maps.android:android-maps-utils` (default: `5.0.0`)
- `googleMapsKtxVersion`: version of `com.google.maps.android:maps-ktx` (default: `6.0.1`)
- `googleMapsUtilsKtxVersion`: version of `com.google.maps.android:maps-utils-ktx` (default: `6.0.1`)
- `kotlinxCoroutinesVersion`: version of `org.jetbrains.kotlinx:kotlinx-coroutines-android` and `org.jetbrains.kotlinx:kotlinx-coroutines-core` (default: `1.11.0`)

## Usage

Expand Down
4 changes: 2 additions & 2 deletions example-app-spm/ios/App/CapApp-SPM/Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ let package = Package(
.package(url: "https://github.com/ionic-team/capacitor-swift-pm.git", exact: "9.0.0-alpha.5"),
.package(name: "CapacitorApp", path: "../../../../node_modules/.pnpm/@capacitor+app@9.0.0-alpha.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/app"),
.package(name: "CapacitorGoogleMaps", path: "../../../../plugin"),
.package(name: "CapacitorHaptics", path: "../../../../node_modules/.pnpm/@capacitor+haptics@8.0.0-next.3_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics"),
.package(name: "CapacitorKeyboard", path: "../../../../node_modules/.pnpm/@capacitor+keyboard@8.0.0-next.4_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard"),
.package(name: "CapacitorHaptics", path: "../../../../node_modules/.pnpm/@capacitor+haptics@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics"),
.package(name: "CapacitorKeyboard", path: "../../../../node_modules/.pnpm/@capacitor+keyboard@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard"),
.package(name: "CapacitorStatusBar", path: "../../../../node_modules/.pnpm/@capacitor+status-bar@9.0.0-alpha.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/status-bar")
],
targets: [
Expand Down
4 changes: 2 additions & 2 deletions example-app/android/capacitor.settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ include ':capacitor-google-maps'
project(':capacitor-google-maps').projectDir = new File('../../plugin/android')

include ':capacitor-haptics'
project(':capacitor-haptics').projectDir = new File('../../node_modules/.pnpm/@capacitor+haptics@8.0.0-next.3_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics/android')
project(':capacitor-haptics').projectDir = new File('../../node_modules/.pnpm/@capacitor+haptics@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics/android')

include ':capacitor-keyboard'
project(':capacitor-keyboard').projectDir = new File('../../node_modules/.pnpm/@capacitor+keyboard@8.0.0-next.4_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard/android')
project(':capacitor-keyboard').projectDir = new File('../../node_modules/.pnpm/@capacitor+keyboard@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard/android')

include ':capacitor-status-bar'
project(':capacitor-status-bar').projectDir = new File('../../node_modules/.pnpm/@capacitor+status-bar@9.0.0-alpha.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/status-bar/android')
4 changes: 2 additions & 2 deletions example-app/ios/App/Podfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ def capacitor_pods
pod 'Capacitor', :path => '../../../node_modules/.pnpm/@capacitor+ios@9.0.0-alpha.5_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/ios'
pod 'CapacitorApp', :path => '../../../node_modules/.pnpm/@capacitor+app@9.0.0-alpha.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/app'
pod 'CapacitorGoogleMaps', :path => '../../../plugin'
pod 'CapacitorHaptics', :path => '../../../node_modules/.pnpm/@capacitor+haptics@8.0.0-next.3_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../../node_modules/.pnpm/@capacitor+keyboard@8.0.0-next.4_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard'
pod 'CapacitorHaptics', :path => '../../../node_modules/.pnpm/@capacitor+haptics@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/haptics'
pod 'CapacitorKeyboard', :path => '../../../node_modules/.pnpm/@capacitor+keyboard@9.0.0-next.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/keyboard'
pod 'CapacitorStatusBar', :path => '../../../node_modules/.pnpm/@capacitor+status-bar@9.0.0-alpha.1_@capacitor+core@9.0.0-alpha.5/node_modules/@capacitor/status-bar'
end

Expand Down
12 changes: 5 additions & 7 deletions plugin/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,11 @@ To use certain location features, the SDK requires the following permissions to

This plugin will use the following project variables (defined in your app's `variables.gradle` file):

- `googleMapsPlayServicesVersion`: version of `com.google.android.gms:play-services-maps` (default: `19.2.0`)
- `googleMapsUtilsVersion`: version of `com.google.maps.android:android-maps-utils` (default: `3.19.1`)
- `googleMapsKtxVersion`: version of `com.google.maps.android:maps-ktx` (default: `5.2.1`)
- `googleMapsUtilsKtxVersion`: version of `com.google.maps.android:maps-utils-ktx` (default: `5.2.1`)
- `kotlinxCoroutinesVersion`: version of `org.jetbrains.kotlinx:kotlinx-coroutines-android` and `org.jetbrains.kotlinx:kotlinx-coroutines-core` (default: `1.10.2`)
- `androidxCoreVersion`: version of `androidx.core:core` (default: `1.19.0`)

- `googleMapsPlayServicesVersion`: version of `com.google.android.gms:play-services-maps` (default: `20.0.0`)
- `googleMapsUtilsVersion`: version of `com.google.maps.android:android-maps-utils` (default: `5.0.0`)
- `googleMapsKtxVersion`: version of `com.google.maps.android:maps-ktx` (default: `6.0.1`)
- `googleMapsUtilsKtxVersion`: version of `com.google.maps.android:maps-utils-ktx` (default: `6.0.1`)
- `kotlinxCoroutinesVersion`: version of `org.jetbrains.kotlinx:kotlinx-coroutines-android` and `org.jetbrains.kotlinx:kotlinx-coroutines-core` (default: `1.11.0`)

## Usage

Expand Down
10 changes: 5 additions & 5 deletions plugin/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ ext {
androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.3.0'
androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.7.0'
androidxCoreVersion = project.hasProperty('androidxCoreVersion') ? rootProject.ext.androidxCoreVersion : '1.19.0'
googleMapsPlayServicesVersion = project.hasProperty('googleMapsPlayServicesVersion') ? rootProject.ext.googleMapsPlayServicesVersion : '19.2.0'
googleMapsUtilsVersion = project.hasProperty('googleMapsUtilsVersion') ? rootProject.ext.googleMapsUtilsVersion : '3.19.1'
googleMapsKtxVersion = project.hasProperty('googleMapsKtxVersion') ? rootProject.ext.googleMapsKtxVersion : '5.2.1'
googleMapsUtilsKtxVersion = project.hasProperty('googleMapsUtilsKtxVersion') ? rootProject.ext.googleMapsUtilsKtxVersion : '5.2.1'
kotlinxCoroutinesVersion = project.hasProperty('kotlinxCoroutinesVersion') ? rootProject.ext.kotlinxCoroutinesVersion : '1.10.2'
googleMapsPlayServicesVersion = project.hasProperty('googleMapsPlayServicesVersion') ? rootProject.ext.googleMapsPlayServicesVersion : '20.0.0'
googleMapsUtilsVersion = project.hasProperty('googleMapsUtilsVersion') ? rootProject.ext.googleMapsUtilsVersion : '5.0.0'
googleMapsKtxVersion = project.hasProperty('googleMapsKtxVersion') ? rootProject.ext.googleMapsKtxVersion : '6.0.1'
googleMapsUtilsKtxVersion = project.hasProperty('googleMapsUtilsKtxVersion') ? rootProject.ext.googleMapsUtilsKtxVersion : '6.0.1'
kotlinxCoroutinesVersion = project.hasProperty('kotlinxCoroutinesVersion') ? rootProject.ext.kotlinxCoroutinesVersion : '1.11.0'
}

buildscript {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ import com.google.maps.android.clustering.view.DefaultClusterRenderer

class CapacitorClusterManagerRenderer(
context: Context,
map: GoogleMap?,
clusterManager: ClusterManager<CapacitorGoogleMapMarker>?,
map: GoogleMap,
clusterManager: ClusterManager<CapacitorGoogleMapMarker>,
minClusterSize: Int?
) : DefaultClusterRenderer<CapacitorGoogleMapMarker>(context, map, clusterManager) {

init {
if(minClusterSize != null && minClusterSize > 0) {
super.setMinClusterSize(minClusterSize)
super.minClusterSize = minClusterSize
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import kotlinx.coroutines.*
import kotlinx.coroutines.channels.Channel
import java.io.InputStream
import java.net.URL
import kotlin.time.Duration.Companion.milliseconds

class CapacitorGoogleMap(
val id: String,
Expand Down Expand Up @@ -116,10 +117,10 @@ class CapacitorGoogleMap(

if (config.mapTypeId != null) {
when (config.mapTypeId!!) {
"hybrid" -> googleMap?.mapType = GoogleMap.MAP_TYPE_HYBRID
"roadmap" -> googleMap?.mapType = GoogleMap.MAP_TYPE_NORMAL
"satellite" -> googleMap?.mapType = GoogleMap.MAP_TYPE_SATELLITE
"terrain" -> googleMap?.mapType = GoogleMap.MAP_TYPE_TERRAIN
"hybrid" -> googleMap?.mapType = MAP_TYPE_HYBRID
"roadmap" -> googleMap?.mapType = MAP_TYPE_NORMAL
"satellite" -> googleMap?.mapType = MAP_TYPE_SATELLITE
"terrain" -> googleMap?.mapType = MAP_TYPE_TERRAIN
}
}

Expand Down Expand Up @@ -152,7 +153,7 @@ class CapacitorGoogleMap(
CoroutineScope(Dispatchers.Main).launch {
val bridge = delegate.bridge
val mapRect = getScaledRect(bridge, updatedBounds)
val mapView = this@CapacitorGoogleMap.mapView;
val mapView = this@CapacitorGoogleMap.mapView
mapView.x = mapRect.left
mapView.y = mapRect.top
if (mapView.layoutParams.width != config.width || mapView.layoutParams.height != config.height) {
Expand All @@ -176,16 +177,6 @@ class CapacitorGoogleMap(
}
}

fun bringToFront() {
CoroutineScope(Dispatchers.Main).launch {
val mapViewParent =
((delegate.bridge.webView.parent) as ViewGroup).findViewWithTag<ViewGroup>(
this@CapacitorGoogleMap.id
)
mapViewParent.bringToFront()
}
}

fun destroy() {
runBlocking {
val job =
Expand Down Expand Up @@ -215,15 +206,15 @@ class CapacitorGoogleMap(

CoroutineScope(Dispatchers.Main).launch {
val tileProvider = object : UrlTileProvider(256, 256) {
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL? {
override fun getTileUrl(x: Int, y: Int, zoom: Int): URL {
return URL(tileOverlay.url
.replace("{x}", "$x")
.replace("{y}", "$y")
.replace("{z}", "$zoom")
)
}
}
var tileOverlayOptions = TileOverlayOptions().tileProvider(tileProvider)
val tileOverlayOptions = TileOverlayOptions().tileProvider(tileProvider)
if (tileOverlay.zIndex != null) {
tileOverlayOptions.zIndex(tileOverlay.zIndex!!)
}
Expand Down Expand Up @@ -369,7 +360,7 @@ class CapacitorGoogleMap(

CoroutineScope(Dispatchers.Main).launch {
newCircles.forEach {
var circleOptions: Deferred<CircleOptions> = CoroutineScope(Dispatchers.IO).async {
val circleOptions: Deferred<CircleOptions> = CoroutineScope(Dispatchers.IO).async {
this@CapacitorGoogleMap.buildCircle(it)
}

Expand Down Expand Up @@ -416,18 +407,20 @@ class CapacitorGoogleMap(
}

private fun setClusterManagerRenderer(minClusterSize: Int?) {
clusterManager?.renderer = CapacitorClusterManagerRenderer(
val map = googleMap ?: return
val manager = clusterManager ?: return
manager.renderer = CapacitorClusterManagerRenderer(
delegate.bridge.context,
googleMap,
clusterManager,
map,
manager,
minClusterSize
)
}

@SuppressLint("PotentialBehaviorOverride")
fun enableClustering(minClusterSize: Int?, callback: (error: GoogleMapsError?) -> Unit) {
try {
googleMap ?: throw GoogleMapNotAvailable()
val map = googleMap ?: throw GoogleMapNotAvailable()

CoroutineScope(Dispatchers.Main).launch {
if (clusterManager != null) {
Expand All @@ -437,7 +430,7 @@ class CapacitorGoogleMap(
}

val bridge = delegate.bridge
clusterManager = ClusterManager(bridge.context, googleMap)
clusterManager = ClusterManager(bridge.context, map)

setClusterManagerRenderer(minClusterSize)
setClusterListeners()
Expand Down Expand Up @@ -667,7 +660,7 @@ class CapacitorGoogleMap(
"Normal"
}
}
callback(mapType, null);
callback(mapType, null)
}
} catch (e: GoogleMapsError) {
callback("", e)
Expand Down Expand Up @@ -815,14 +808,14 @@ class CapacitorGoogleMap(
polygonOptions.clickable(polygon.clickable)

var shapeCounter = 0
polygon.shapes.forEach {
polygon.shapes.forEach { pointList ->
if (shapeCounter == 0) {
// outer shape
it.forEach {
pointList.forEach {
polygonOptions.add(it)
}
} else {
polygonOptions.addHole(it)
polygonOptions.addHole(pointList)
}

shapeCounter += 1
Expand Down Expand Up @@ -856,7 +849,7 @@ class CapacitorGoogleMap(

private fun buildMarker(marker: CapacitorGoogleMapMarker): MarkerOptions {
val markerOptions = MarkerOptions()
markerOptions.position(marker.coordinate)
markerOptions.position(marker.position)
markerOptions.title(marker.title)
markerOptions.snippet(marker.snippet)
markerOptions.alpha(marker.opacity)
Expand All @@ -874,13 +867,12 @@ class CapacitorGoogleMap(
markerOptions.icon(getResizedIcon(cachedBitmap!!, marker))
} else {
try {
var stream: InputStream? = null
if (marker.iconUrl!!.startsWith("https:")) {
stream = URL(marker.iconUrl).openConnection().getInputStream()
val stream: InputStream? = if (marker.iconUrl!!.startsWith("https:")) {
URL(marker.iconUrl).openConnection().getInputStream()
} else {
stream = this.delegate.context.assets.open("public/${marker.iconUrl}")
this.delegate.context.assets.open("public/${marker.iconUrl}")
}
var bitmap = BitmapFactory.decodeStream(stream)
val bitmap = BitmapFactory.decodeStream(stream)
this.markerIcons[marker.iconUrl!!] = bitmap
markerOptions.icon(getResizedIcon(bitmap, marker))
} catch (e: Exception) {
Expand All @@ -907,20 +899,20 @@ class CapacitorGoogleMap(
}

private fun getResizedIcon(
_bitmap: Bitmap,
marker: CapacitorGoogleMapMarker
bitmap: Bitmap,
marker: CapacitorGoogleMapMarker
): BitmapDescriptor {
var bitmap = _bitmap
var updatedBitmap = bitmap
if (marker.iconSize != null) {
bitmap =
updatedBitmap =
Bitmap.createScaledBitmap(
bitmap,
updatedBitmap,
(marker.iconSize!!.width * this.config.devicePixelRatio).toInt(),
(marker.iconSize!!.height * this.config.devicePixelRatio).toInt(),
false
)
}
return BitmapDescriptorFactory.fromBitmap(bitmap)
return BitmapDescriptorFactory.fromBitmap(updatedBitmap)
}

fun onStart() {
Expand Down Expand Up @@ -1142,7 +1134,7 @@ class CapacitorGoogleMap(
override fun onCameraMove() {
debounceJob?.cancel()
debounceJob = CoroutineScope(Dispatchers.Main).launch {
delay(100)
delay(100.milliseconds)
clusterManager?.cluster()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ import org.json.JSONObject


class CapacitorGoogleMapMarker(fromJSONObject: JSONObject): ClusterItem {
var coordinate: LatLng = LatLng(0.0, 0.0)
private var coordinate: LatLng = LatLng(0.0, 0.0)
var opacity: Float = 1.0f
private var title: String
private var snippet: String
private var zIndex: Float = 0.0f
override var title: String
override var snippet: String
override var zIndex: Float = 0.0f
override val position: LatLng get() = LatLng(coordinate.latitude, coordinate.longitude)
var isFlat: Boolean = false
var iconUrl: String? = null
var iconSize: Size? = null
Expand Down Expand Up @@ -66,22 +67,6 @@ class CapacitorGoogleMapMarker(fromJSONObject: JSONObject): ClusterItem {
zIndex = fromJSONObject.optLong("zIndex").toFloat()
}

override fun getPosition(): LatLng {
return LatLng(coordinate.latitude, coordinate.longitude)
}

override fun getTitle(): String {
return title
}

override fun getSnippet(): String {
return snippet
}

override fun getZIndex(): Float {
return zIndex
}

private fun buildIconAnchorPoint(iconAnchor: CapacitorGoogleMapsPoint): CapacitorGoogleMapsPoint? {
iconSize ?: return null

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
package com.capacitorjs.plugins.googlemaps

import android.graphics.Color
import androidx.core.graphics.toColor
import com.google.android.gms.maps.model.LatLng
import com.google.android.gms.maps.model.Polyline
import org.json.JSONObject

class CapacitorGoogleMapPolyline(fromJSONObject: JSONObject) {
var path: MutableList<LatLng> = mutableListOf<LatLng>()
var styleSpans: MutableList<CapacitorGoogleMapsStyleSpan> = mutableListOf<CapacitorGoogleMapsStyleSpan>()
var path: MutableList<LatLng> = mutableListOf()
var styleSpans: MutableList<CapacitorGoogleMapsStyleSpan> = mutableListOf()
var strokeWidth: Float = 1.0f
var strokeColor: Int = Color.BLUE
var clickable: Boolean
Expand Down Expand Up @@ -68,9 +67,9 @@ class CapacitorGoogleMapPolyline(fromJSONObject: JSONObject) {
val colorInt = Color.parseColor(hex)

val alpha = (opacity * 255.0).toInt()
val red = android.graphics.Color.red(colorInt)
val green = android.graphics.Color.green(colorInt)
val blue = android.graphics.Color.blue(colorInt)
val red = Color.red(colorInt)
val green = Color.green(colorInt)
val blue = Color.blue(colorInt)

return Color.argb(alpha, red, green, blue)
}
Expand Down
Loading
Loading