【发布时间】:2015-11-21 15:02:06
【问题描述】:
我的 HTML(单击按钮后我试图在 div 中插入地图):
...
<div id="map"></div>
...
<button id="location">log your location</button>
<script async defer
src="https://maps.googleapis.com/maps/api/js?key=xxxmyapikeyxxx&callback=">
</script>
...
我的 javascript 代码(我试图遵守 phonegap 规则,通过在 click 中添加 addEventListener 并在单击按钮时创建地图:
...
onDeviceReady: function() {
app.receivedEvent('deviceready');
document.getElementById("camera").addEventListener("click", function() {
navigator.camera.getPicture(function(imagePath){
document.getElementById("photoImg").setAttribute("src", imagePath);
}, function(){
alert("Photo cancelled");
}, {
destinationType: navigator.camera.DestinationType.FILE_URI
});
}, false);
document.getElementById("location").addEventListener("click", function() {
var map;
map = new google.maps.Map(document.getElementById('map'), {
center: {lat: -34.397, lng: 150.644},
zoom: 8
});
});
},
...
当单击 ID 为 location 的按钮时,我正在尝试使用地图填充 ID 为 map 的 div。
【问题讨论】:
-
@dwij 这是问题
标签: javascript ios cordova google-maps phonegap-build