为什么在使用 StageWebView 的 AIR Android 应用程序中尝试实现 Google 地图 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 应用程序,我需要在其中实现地图。环顾四周后,我决定使用 StageWebView class 将 Google 地图 API 用于 Javascript。当我 运行 项目时,我得到这个错误:
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。
它会起作用
谢谢。
我正在开发一个 AIR Android 应用程序,我需要在其中实现地图。环顾四周后,我决定使用 StageWebView class 将 Google 地图 API 用于 Javascript。当我 运行 项目时,我得到这个错误:
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。
它会起作用
谢谢。