【发布时间】:2019-12-18 02:02:00
【问题描述】:
我一直在尝试使用来自https://github.com/mapsplugin/cordova-plugin-googlemaps 的科尔多瓦谷歌地图插件,但还没有让它在我的安卓上顺利运行。
我找到了代码
我已经为谷歌地图尝试了其他几个 github 存储库,但仍然没有运气。
<q-page class="q-pa-xl">
<h1>Hello, World!</h1>
<div id="map_canvas">
<button id="button">Click me!</button>
</div>
</q-page>
</template>
<script>
export default {
name: 'Map',
created () {
// Vuex get the map lat/lng
document.addEventListener('deviceready', () => {
var div = document.getElementById('map_canvas')
// Create a Google Maps native view under the map_canvas div.
//var map = plugin.google.maps.Map.getMap(div)
var map = window.plugin.google.maps.Map.getMap(div)
// If you click the button, do something...
var button = document.getElementById('button')
button.addEventListener('click', function () {
// Move to the position with animation
map.animateCamera({
target: {lat: 37.422359, lng: -122.084344},
zoom: 17,
tilt: 60,
bearing: 140,
duration: 5000
})
// Add a maker
var marker = 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: window.plugin.google.maps.Animation.BOUNCE
})
// Show the info window
marker.showInfoWindow()
})
}, false)
}
}
</script>
我也在 src-cordova 的 config.xml 文件中添加了<preference name="GOOGLE_MAPS_ANDROID_API_KEY" value="my api key" />。我试图在我的手机上测试该应用程序,但它卡在 Apache Cordova 设备已准备好闪烁。
【问题讨论】:
-
您遇到了什么错误,您的地图是什么样的?如果在浏览器平台上运行地图会加载吗?还要仔细检查您是否添加了有效的 API 密钥并为您的项目启用了 Maps API 和计费。
标签: javascript google-maps cordova cordova-plugins quasar-framework