<div class="pad" style="height: 450px;" id="test"></div>
let boolean = new Boolean(); $.ajax({ url: 'https://webapi.amap.com/maps?v=1.4.15&key=您申請的key值', success: function(result){ boolean = true; }, error: function(result){ alert("無網絡鏈接,暫不支持地圖查看!"); boolean = false; $("#servermap").attr("class","hidden"); } }); if (boolean) { document.getElementById("test").innerHTML = '<object type="text/html" data="GaodeMap.html" width="100%" height="100%"></object>'; }
這樣加載可能會有卡頓又修改了下,這樣會在ajax響應的時候出現正在加載地圖css
$.ajax({ timeout: 1500, url: 'https://webapi.amap.com/maps?v=1.4.15&key=您申請的key值', success: function(result){ document.getElementById("test").innerHTML = '<object type="text/html" data="GaodeMap.html" width="100%" height="100%"></object>'; }, beforeSend: function(){ $("#test").css("text-align","center"); $('#test').html('正在加載地圖,請稍等。。。。'); }, error: function(result){ $("#test").attr("style","height: 100px"); document.getElementById("test").innerHTML = '<center>無網絡鏈接,暫不支持地圖查看</center>'; } });
具體的html地圖文件高德地圖api能夠本身畫html