Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error while initializing map on IOS device #53

Open
yiannis-spyridakis opened this issue Oct 16, 2024 · 2 comments
Open

Error while initializing map on IOS device #53

yiannis-spyridakis opened this issue Oct 16, 2024 · 2 comments
Labels

Comments

@yiannis-spyridakis
Copy link

Bug Report

I am getting a crash while running ann app that uses @capacitor/google-maps on a test device (iPhone 8). The app crashes in Map.enableCurrentLocation and the error is:

Thread 1: Fatal error: Unexpectedly found nil while implicitly unwrapping an Optional value

Which is caused by self.mapViewController.GMapView not being initialized.

Plugin(s)

@capacitor/google-maps

Capacitor Version

💊   Capacitor Doctor  💊 

Latest Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

Installed Dependencies:

  @capacitor/cli: 6.1.2
  @capacitor/core: 6.1.2
  @capacitor/android: 6.1.2
  @capacitor/ios: 6.1.2

[success] iOS looking great! 👌
[success] Android looking great! 👌

Platform(s)

IOS

Current Behavior

Crash on (I am guessing) certain device/ app setup combinations when loading map

Expected Behavior

Fix

Code Reproduction

I have debugged the plugin and the issue originates in Map.getTargetContainer

    private func getTargetContainer(refWidth: Double, refHeight: Double) -> UIView? {
        if let bridge = self.delegate.bridge {
            for item in bridge.webView!.getAllSubViews() {
                let isScrollView = item.isKind(of: NSClassFromString("WKChildScrollView")!) || item.isKind(of: NSClassFromString("WKScrollView")!)
                let isBridgeScrollView = item.isEqual(bridge.webView?.scrollView)

                if isScrollView && !isBridgeScrollView {
                    (item as? UIScrollView)?.isScrollEnabled = true

                    let height = Double((item as? UIScrollView)?.contentSize.height ?? 0)
                    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

                    if isWidthEqual && isHeightEqual && item.tag < self.targetViewController?.tag ?? Map.MAP_TAG {
                        return item
                    }
                }
            }
        }

        return nil
    }

In the function above isHeightEqual is always false. In the case of the 'correct' view it is off by one (367.0 <> 366.0) which, I am guessing has to do with the specific dimensions of my device and some rounding error.

This works for me:

                    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
                    }
@ionitron-bot ionitron-bot bot added the triage label Oct 16, 2024
yiannis-spyridakis added a commit to yiannis-spyridakis/capacitor-google-maps that referenced this issue Oct 16, 2024
yiannis-spyridakis added a commit to yiannis-spyridakis/capacitor-google-maps that referenced this issue Oct 17, 2024
- Updated IOS Map.buildMarker to also support base64 data urls
- Bumped version to 6.0.3
@Geschan
Copy link

Geschan commented Oct 17, 2024

Experiencing the same issue on iPhone 13 Pro. GMapView is not being properly initialized and causing our app to crash if any setting like setMapType is called.

@Geschan
Copy link

Geschan commented Oct 18, 2024

On our test device, the issue went away when we set a fixed height (we had a variable height of 35vh) for the maps element. We will monitor our crash logs to see if that's true for all iPhone models that have been affected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants