androidgoogle-mapswebviewandroid-webview

What is the minimum version of Android System WebView that supports Google maps now?


Our application integrates a web version of Google maps for devices without Google services. The page displaying maps in the application imports the following JavaScript: https://maps.googleapis.com/maps/api/js?sensor=true&key=our_key . The problem is that in older versions of WebView this script does not work correctly and always returns an error:

Uncaught SyntaxError: Unexpected token ?
Uncaught ReferenceError: google is not defined

It was experimentally found out that this script works correctly in version 106 of WebView and definitely does not work in 76. Who can tell me in what minimum version of Android System WebView Google maps work correctly now?

We don't plan to fix Google maps on old devices, but we want to hide WebView with Google maps for old devices where this script does not work correctly.


Solution

  • Now I use this solution in my project.

    fun WebView.isGoogleMapsSupported(): Boolean = (getVersion() ?: 0) >= 96 //with min version Android 6.0 and newer
    
    fun WebView.getVersion(): Int? {
        val userAgent = getSettings().userAgentString
        val chromeRegex = Pattern.compile("[Cc]hrome/[0-9]+([.][0-9]+){0,3}")
        val chromeMatcher = chromeRegex.matcher(userAgent)
        if (chromeMatcher.find()) {
            val chromeString = chromeMatcher.group()
            if (chromeString.length > 7) {
                val fullVersion = chromeString.substring(7)
                return fullVersion.substring(0, fullVersion.indexOf('.')).toIntOrNull()
            }
        }
        return null
    }