PhoneGap Cordova插件谷歌地图 - 插件未定义

时间:2018-05-19 22:40:38

标签: android cordova cordova-plugins phonegap-plugins phonegap

任何帮助或建议都会很棒!

我在Android log的logcat中收到这些错误

05-18 23:02:41.917 13209-13209/? D/SystemWebChromeClient: file:///data/user/0/com.adobe.phonegap.app/files/phonegapdevapp/www/index.html: Line 350 : Uncaught ReferenceError: plugin is not defined
05-18 23:02:41.917 13209-13209/? I/chromium: [INFO:CONSOLE(350)] "Uncaught ReferenceError: plugin is not defined", source: file:///data/user/0/com.adobe.phonegap.app/files/phonegapdevapp/www/index.html (350)

我试过了:

  • 从头开始重新启动 - 创建了多个新实例 应用

  • 不同类型的安装 - 手动和使用终端

  • 查看多个堆栈溢出条目并尝试删除 并重新添加插件,android平台,配置文件

插件:

$ phonegap plugins
cordova-plugin-googlemaps 2.3.4-beta-20180517-1004 "cordova-plugin-googlemaps"

我的代码:

   <!DOCTYPE html>
<html>
  <head>
    <meta name="viewport" content="width=device-width">
    <script type="text/javascript" src="cordova.js"></script>
    <script type="text/javascript">
      document.addEventListener("deviceready", function() {

        var map = plugin.google.maps.Map.getMap("map_canvas");

      }, false);

    </script>
    <style type="text/css">
    #map_canvas {
      width: 500px;
      height: 500px;
    }
    button {
      padding: .5em;
      margin: .5em;
    }
    </style>
  </head>
  <body>
    <h1>Hello, World!</h1>
    <button id="button">Click me!</button>
    <div id="map_canvas"></div>
  </body>
</html>

我的目录:

Directory

2 个答案:

答案 0 :(得分:0)

我没有使用google地图的cordova插件,但我使用旧的方式显示谷歌地图及其工作。您需要注册Google API并获取API ID。它应该与此类似

<script async defer src="https://maps.googleapis.com/maps/api/js?key=[Your API ID provided by google]&callback=[Your function when API is loaded] "></script>

<script>
        function initMap() {
            var map = new google.maps.Map(document.getElementById('map_canvas'), {
              zoom: 18,
              center: {lat: [Your map latitude value], lng: [Your map Longitude value]}
            });
            var geocoder = new google.maps.Geocoder();
            geocodeAddress(geocoder, map);
        }

        function geocodeAddress(geocoder, resultsMap) {
            geocoder.geocode({'address': address}, function(results, status) {
              if (status === 'OK') {
                resultsMap.setCenter(results[0].geometry.location);
                var marker = new google.maps.Marker({
                  map: resultsMap,
                  position: results[0].geometry.location
                });
              } else {
                alert('Geocode was not successful for the following reason: ' + status);
              }
            });
        }
</script>

答案 1 :(得分:0)

cordova-plugin-googlemaps无法与$> phongep servephonegap developer app一同投放。

您必须在真实设备或模拟器上构建和运行项目

$> phonegap cordova run android