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

Posted

技术标签:

【中文标题】PhoneGap Cordova 插件谷歌地图 - 插件未定义【英文标题】:PhoneGap Cordova plugin google maps - Plugin not defined 【发布时间】:2018-10-30 00:07:25 【问题描述】:

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

我在 android Studio 的 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>

我的目录:

【问题讨论】:

【参考方案1】:

我没有使用谷歌地图的科尔多瓦插件,但我使用旧的方式来显示谷歌地图及其工作。您需要注册 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>

【讨论】:

我有 API 密钥,并且可以使用 Google 地图中的 Javascript API 运行它,但我试图利用该插件。【参考方案2】:

cordova-plugin-googlemaps 不能使用 $&gt; phongep servephonegap developer app 运行。

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

$> phonegap cordova run android

【讨论】:

以上是关于PhoneGap Cordova 插件谷歌地图 - 插件未定义的主要内容,如果未能解决你的问题,请参考以下文章

Phonegap GPS定位插件cordova-plugin-gpslocation

Quasar Cordova 谷歌地图插件

iphone phonegap 谷歌地图内存警告

Phonegap/Cordova 地理定位提醒特定位置附近有啥

如何在 phonegap 构建中使用谷歌播放服务插件

Cordova/Phonegap:无法让 Facebook Phonegap 插件工作