jQuery和Google Maps JS API不能一起使用 [英] JQuery and Google Maps JS api not working together
问题描述
我真的很难在同一块中同时使用Google Maps API和JQuery API.我的页面是jspx(春季),我需要JQuery,以便我可以获取和解析Google融合表数据.
I am really stuck trying to use both the Google Maps API and the JQuery API in the same block.. My page is jspx (Spring) and I need the JQuery so that I can get and parse google fusion table data.
但是,当我同时声明两个库时,map div将不会加载(如果我单独加载Google Maps,则所有映射都可以正常工作).
However, when I declare both libraries together the map div will not load (if I load Google Maps alone, all of the mapping works fine).
以下是相关代码:
<script src="http://code.jquery.com/jquery-latest.pack.js" type="text/javascript"/>
<script src="http://maps.googleapis.com/maps/api/js?v=3key=MYKEY&sensor=false" type="text/javascript">
<jsp:text/>
</script>
<script type="text/javascript">
//<![CDATA[
var map;
function initialize() {
var mapDiv = document.getElementById('map_canvas');
var geocoder = new google.maps.Geocoder();
retrieveDeprivationFigure();
if (geocoder) {
geocoder.geocode({ 'address': '${property.postcode}' }, function (results, status) {
if (status == google.maps.GeocoderStatus.OK) {
var latlng = new google.maps.LatLng(results[0].geometry.location.lat(), results[0].geometry.location.lng())
var mapOptions = {
zoom: 15,
center: latlng,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
map = new google.maps.Map(document.getElementById('map_canvas'),
mapOptions);
}
function retrieveDeprivationFigure(){
var postcode = '${property.postcode}'.split(' ').join('');
var url = "https://www.googleapis.com/fusiontables/v1/query?sql=SELECT LSOA FROM XXXXXXXX WHERE Postcode='"+ postcode +"'&key=AIzaSyBQaHw1aSWtIjQzAiriBPC3hvm7Bs1R35U&jsonCallback=?";
var localIMDS;
console.log("this far");
$.getJSON(url,
function retrieveIMDS(){
console.log(url);
});
};
google.maps.event.addDomListener(window, 'load', initialize);
// ]]>
</script>
任何指针或想法都会对我有很大帮助,我什至尝试通过单独的JS块中的JQuery检索剥夺状态,但是尽管我付出了很多努力,但并未在页面加载时调用该函数.
Any pointers or ideas would help me greatly, I even tried retrieving the deprivation stat via JQuery in a seperate JS block, however despite my efforts, the function was not called on page load.
推荐答案
感谢指导人员,但我设法通过创建一个head并在head文件中声明jQuery并离开Google来对冲突和问题进行排序src所在的位置.
Thanks for the guidance guys, but I managed to sort the conflicts and issues by creating a head and declaring the jQuery in the head file instead, and leaving the google src where it was.
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.1.js"></script>
<script type="text/javascript">
</script>
</head>
再次感谢!
这篇关于jQuery和Google Maps JS API不能一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!