带有 Google 地图的 Cordova 抛出 "Update Google Play Services"

Cordova with Google Maps throws "Update Google Play Services"

我从 c​​ordova 和 google map 插件开始。我安装了 Java 和 android 工作室。

另外,我为 API 25 下载了一个 google api 图像,我也配置了一个 AVD 图像。

我的问题是当我 运行 我的虚拟设备时,我收到 "Update Google Play Services" 消息。而且,如您所见,地图默认应用程序运行良好(见屏幕截图)

我添加了这个插件:

我的代码如下所示:

<html>
    <head>        
        <meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
        <meta name="format-detection" content="telephone=no">
        <meta name="msapplication-tap-highlight" content="no">
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
        <link rel="stylesheet" type="text/css" href="css/index.css">
        <title>Hello World</title>
    </head>
    <body>
        <div class="app">
            <h1>Apache Cordova</h1>
            <div id="deviceready" class="blink">
                <p class="event listening">Connecting to Device</p>
                <p id="result" class="event received">Hi!</p>

            </div>
        </div>
        <div style="width:100%;height:400px" id="map_canvas"></div>
        <script type="text/javascript" src="cordova.js"></script>
        <script type="text/javascript" src="js/index.js"></script>
    </body>
</html>

我的javascript如下:

var map;
var app = {

    // Application Constructor
    initialize: function() {
        document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
    },

    // deviceready Event Handler
    onDeviceReady: function() {
        this.receivedEvent('deviceready');

        // onSuccess Callback        
        var onSuccess = function(position) {
            var el = document.getElementById("result");
            el.innerHTML = 'Latitude: ' + position.coords.latitude;


            var div = document.getElementById("map_canvas");

            // Initialize the map view
            map = plugin.google.maps.Map.getMap(div);

            // Wait until the map is ready status.
            map.addEventListener(plugin.google.maps.event.MAP_READY, function() {
                var button = document.getElementById("button");
                //button.addEventListener("click", onBtnClicked);
            });
        }

        // onError Callback receives a PositionError object
        function onError(error) {
            var el = document.getElementById("result");
            el.innerHTML = 'code: ' + error.code + 'message: ' + error.message;            
        }

        navigator.geolocation.getCurrentPosition(onSuccess, onError, { timeout: 30000, enableHighAccuracy: true, maximumAge: 60000 });
    },

    // Update DOM on a Received Event
    receivedEvent: function(id) {
        var parentElement = document.getElementById(id);
        var listeningElement = parentElement.querySelector('.listening');
        var receivedElement = parentElement.querySelector('.received');

        listeningElement.setAttribute('style', 'display:none;');
        receivedElement.setAttribute('style', 'display:block;');

        console.log('Received Event: ' + id);
    }
};

部分截图:

好的,我终于找到了解决方案。

  1. 在 android 模拟设备中:设置 > 应用 > Google Play 服务; 获取应用程序版本。就我而言,是 9.8.77
  2. -android sdk folder-\extras\google\m2repository\com\google\android\gms\play-services-maps, 获得等于或低于已安装版本的最大版本。在我的 案例是 9.8.0
  3. -project folder-\platforms\android\project.properties中,更改 这个:

cordova.system.library.1=com.google.android.gms:play-services-maps:+ cordova.system.library.2=com.google.android.gms:play-services-location:+

对于

cordova.system.library.1=com.google.android.gms:play-services-maps:9.8.0 cordova.system.library.2=com.google.android.gms:play-services-location:9.8.0

其中“9.8.0”为第2点获取的版本

根据创建和管理虚拟设备中的 setting in your manifest as recommended in System image,您可能想尝试为您的应用可能支持的每个 API 级别创建一个 AVD。

Viewing and Managing Your AVDs 中的进一步讨论还指出,如果您为 Android Emulator 24.0.x 或更低版本定义了 AVD,您可能还需要重新创建定义的 AVD 或复制它们。

以下是从副本开始创建 AVD 的步骤:

  1. From the Your Virtual Devices page of the AVD Manager, right-click an AVD and select Duplicate. Or click Menu and select Duplicate.

The Verify Configuration page appears.

  1. Click Change or Previous if you need to make changes on the System Image and Select Hardware pages.
  2. Make your changes, and then click Finish. The AVD appears in the Your Virtual Devices page.

以下相关 SO 帖子中给出的解决方案也可能有所帮助:

  • “This app won't run unless you update google play services” alert
  • This app won't run unless you update Google Play services error