繁体   English   中英

尝试使用StageWebView在AIR Android应用程序中实现Google Maps JavaScript API时,为什么会出现“ InvalidValueError”错误?

[英]Why am I getting “InvalidValueError” error when trying to implement Google Maps JavaScript API in an AIR Android application using StageWebView?

我正在开发AIR Android应用程序,需要在其中实现Maps。 环顾四周后,我决定通过StageWebView类使用Java的Google Maps API。 当我运行项目时,出现以下错误:

InvalidValueError: initMap is not a function
    at https://maps.googleapis.com/maps/api/js?     key=XXXXXXXXXX%20%20%20%20%20%20%20%20&libraries=visualization&callback=initMap : 87
 at https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXX%20%20%20%20%20%20%20%20&libraries=visualization&callback=initMap : 123
 at https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXX%20%20%20%20%20%20%20%20&libraries=visualization&callback=initMap : 21
 at https://maps.googleapis.com/maps/api/js?key=XXXXXXXXXX%20%20%20%20%20%20%20%20&libraries=visualization&callback=initMap : 123

这是HTML:

<!DOCTYPE html>
<html>
  <head>
    <style type="text/css">
      html, body { height: 100%; margin: 0; padding: 0; }
      #map { height: 100%; }
    </style>
  </head>
  <body>
    <div id="map"> </div>
    <script async defer
        src="https://maps.googleapis.com/maps/api/js?key=xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
        &libraries=visualization&callback=initMap">
    </script>
    <script src="map.js"> </script>
  </body>
</html>

JS:

function initMap() {
  var map = new google.maps.Map(document.getElementById('map'), {
    center: {lat: 0, lng: 0},
    zoom: .3,
    styles: [{
      featureType: 'poi',
      stylers: [{ visibility: 'off' }]  // Turn off points of interest.
    }, {
      featureType: 'transit.station',
      stylers: [{ visibility: 'off' }]  // Turn off bus stations, train stations, etc.
    }],
    disableDoubleClickZoom: true
  });

     map.addListener('click', function(e) {
  var marker = new google.maps.Marker({
    position: {lat: e.latLng.lat(), lng: e.latLng.lng()},
    map: map
  });
console.log(e.latLng.lat(), e.latLng.lng());
});
}

AS3:

var webView:StageWebView;
var file:File = File.applicationDirectory.resolvePath("gmaps/gmaps.html");
var mapURL:String = file.nativePath;

webView = new StageWebView();
webView.stage = stage;
webView.viewPort = new Rectange(0, 0, stage.stageWidth, stage.stageHeight);
webView.loadURL(mapURL);

注意:在chrome中运行gmaps.html文件非常有效。

那么,有什么问题呢? 由于我没有使用JS / HTML的经验,所以我不能说真的。 我确实尝试过使用google,但这也无济于事。 任何帮助是极大的赞赏

如果您尝试在脚本异步处理之前调用map.js。

会的

谢谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM