【发布时间】:2018-01-22 21:25:57
【问题描述】:
同学们,
我正在尝试使用 cordova-plugin-googlemaps 制作 Phonegap/Cordova(和 Framework7)以与 Vuejs 一起使用。尽管一切正常,但地图并未加载。
代码如下:
<template>
<f7-page name="mapa">
<div id="mapcanvas"></div>
</f7-page>
</template>
<script>
var map;
let deviceReady = false;
let vueMounted = false;
export default {
name: 'Mapa',
data() {
return {
isConnected: false,
map: undefined
}
},
created () {
vueMounted = true;
if (deviceReady) this.everythingReady();
},
methods: {
everythingReady() {
var div = document.getElementById("mapcanvas");
map = plugin.google.maps.Map.getMap(div);
map.addEventListener(plugin.google.maps.event.MAP_READY, this.onMapReady);
},
onMapReady(){
alert("mapa pronto");
},
onButtonClick() {
map.animateCamera({
target: {lat: 37.422359, lng: -122.084344},
zoom: 17,
tilt: 60,
bearing: 140,
duration: 5000
}, function() {
map.addMarker({
position: {lat: 37.422359, lng: -122.084344},
title: "Welecome to \n" +
"Cordova GoogleMaps plugin for iOS and Android",
snippet: "This plugin is awesome!",
animation: plugin.google.maps.Animation.BOUNCE
}, function(marker) {
marker.showInfoWindow()
marker.on(plugin.google.maps.event.INFO_CLICK, function() {
alert("Hello world!")
});
});
});
},
}
}
document.addEventListener('deviceReady', () => {
deviceReady = true
if (vueMounted) this.everythingReady()
}, false);
</script>
<style>
#mapcanvas{
height: 100vh;
width: 100vw;
position:absolute;
top: 0;
left: 0;
}
canvas{
display: block;
}
</style>
执行了onMapReady()方法,但是地图没有打印出来。
更新: 我稍微更改了代码以确保在创建 Vuejs 模块后执行代码,并且还触发了 deviceready 侦听器。但是没有成功!
任何想法可能是什么问题?
【问题讨论】:
标签: cordova vuejs2 cordova-plugins phonegap html-framework-7