Jquery代码没有';我不在jQuery移动项目中工作
我正在使用jQuery移动库与Cordova开发一个混合应用程序。 因为我需要显示一张地图,我使用并编辑了找到的代码,但它似乎无法识别代码的第一行 Geolocation.jsJquery代码没有';我不在jQuery移动项目中工作,jquery,cordova,jquery-mobile,google-maps-api-3,maps,Jquery,Cordova,Jquery Mobile,Google Maps Api 3,Maps,我正在使用jQuery移动库与Cordova开发一个混合应用程序。 因为我需要显示一张地图,我使用并编辑了找到的代码,但它似乎无法识别代码的第一行 Geolocation.js $(document).on("pagecreate", "#map-page", function() { //doesn't work alert('hello'); function initMap() { var defaultLatLng = new google.maps.L
$(document).on("pagecreate", "#map-page", function() { //doesn't work
alert('hello');
function initMap() {
var defaultLatLng = new google.maps.LatLng(44.494887, 11.342616300000032); //Bologna
drawMap(defaultLatLng);
}
function drawMap(latlng) {
var myOptions = {
zoom: 17,
center: latlng,
};
var map = new google.maps.Map(document.getElementById("map-canvas"), myOptions);
var marker = new google.maps.Marker({
position: latlng,
map: map,
title: "Parcheggio"
});
}
});
Html容器与演示相同。我包含的脚本包括:
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/geolocation.js"></script>
<script type="text/javascript" src="js/jquery-1.11.3.min.js"></script>
<script type="text/javascript" src="js/jquery.mobile-1.4.5/jquery.mobile-1.4.5.min.js"></script>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD91dMkAWwADchy-WY1-5O7P6nHmjGont0
&callback=initMap"></script>
我还尝试更改API密钥,但没有任何更改。
您知道如何解决此问题吗?您应该在
document.ready
块中移动事件绑定
$(document).ready(function(){
$(document).on("pagecreate", "#map-page", function() {
....
});
});
另外,在jquery包含之后包含Geolocation.js。您可以尝试这个答案中的方法,它提供了一些关于在Cordova应用程序中放置初始化代码的好信息:谢谢,但仍然不起作用。看起来它不读取以$(document)开头的代码,也不读取以$.@MonicaKiur开头的代码-您在jquery.js之前包含了geolocation.js。需要更改订单。请现在检查,我更改了订单。现在它可以工作了,但仍然没有加载map@MonicaKiur-很高兴知道这件事。为此,我请你再发一个问题。当然。非常感谢你的帮助。