Skip to content

Commit

Permalink
- Fix for map crashing on certain IOS devices (ionic-team#53)
Browse files Browse the repository at this point in the history
- Updated IOS Map.buildMarker to also support base64 data urls
- Bumped version to 6.0.3
  • Loading branch information
yiannis-spyridakis committed Oct 17, 2024
1 parent 970a624 commit 98dd19d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ package-lock.json
Podfile.lock
Package.resolved
.env
test.sh
test.sh
plugin
.vscode
21 changes: 18 additions & 3 deletions ios/Plugin/Map.swift
Original file line number Diff line number Diff line change
Expand Up @@ -182,8 +182,9 @@ public class Map {
let width = Double((item as? UIScrollView)?.contentSize.width ?? 0)
let actualHeight = round(height / 2)

let isWidthEqual = width == self.config.width
let isHeightEqual = actualHeight == self.config.height
let tolerance = 1.0
let isWidthEqual = abs(width - self.config.width) <= tolerance
let isHeightEqual = abs(actualHeight - self.config.height) <= tolerance

if isWidthEqual && isHeightEqual && item.tag < self.targetViewController?.tag ?? Map.MAP_TAG {
return item
Expand Down Expand Up @@ -621,7 +622,21 @@ public class Map {
if let iconImage = self.markerIcons[iconUrl] {
newMarker.icon = getResizedIcon(iconImage, marker)
} else {
if iconUrl.starts(with: "https:") {
if iconUrl.starts(with: "data") {
// Handle base64 encoded image
if let dataRange = iconUrl.range(of: "base64,") {
let base64String = String(iconUrl[dataRange.upperBound...])
if let imageData = Data(base64Encoded: base64String, options: .ignoreUnknownCharacters),
let iconImage = UIImage(data: imageData) {
self.markerIcons[iconUrl] = iconImage
newMarker.icon = getResizedIcon(iconImage, marker)
} else {
print("CapacitorGoogleMaps Wanring: could not decode base64 image. Using default marker icon.")
}
} else {
print("CapacitorGoogleMaps Warning: invalid data URL format. Using default marker icon.")
}
} else if iconUrl.starts(with: "https:") {
if let url = URL(string: iconUrl) {
URLSession.shared.dataTask(with: url) { (data, _, _) in
DispatchQueue.main.async {
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@capacitor/google-maps",
"version": "6.0.1",
"version": "6.0.3",
"description": "Google maps on Capacitor",
"main": "dist/plugin.cjs.js",
"module": "dist/esm/index.js",
Expand Down Expand Up @@ -93,4 +93,4 @@
"@googlemaps/markerclusterer": "~2.0.7",
"@types/google.maps": "~3.50.5"
}
}
}

0 comments on commit 98dd19d

Please sign in to comment.