我想在谷歌地圖上添加標記,當我得到AJAX標記數據,並調用initMap
功能後地圖不會加載但經過寫警報()當我添加之前警報initMap
函數,地圖加載。爲什麼我需要調用谷歌地圖API
這部作品,並顯示在地圖和標記:
$('#ddlLatLog').on("change", function() {
jQuery.getJSON('@Url.Action("GetLatLog", "MyTheme", new { area = "" })', {
id: $(this).find('option:selected').attr('Value')
},
function(jdata) {
markermap = jdata;
});
alert(markermap);
initMap(centermap, markermap);
});
不加載地圖
$('#ddlLatLog').on("change", function() {
jQuery.getJSON('@Url.Action("GetLatLog", "MyTheme", new { area = "" })', {
id: $(this).find('option:selected').attr('Value')
},
function(jdata) {
markermap = jdata;
});
// alert(markermap);
initMap(centermap, markermap);
});
調用谷歌API:
<script src="http://maps.google.com/maps/api/js?v=3.26&key=...callback=initMap" async defer></script>
爲什麼我需要提醒?
,因爲你有你的selector.' $缺少的單引號('#ddlLatLog)。在此毫無疑問不起作用在所有'應該是'$( '#ddlLatLog')on' – NewToJS
OPS我忘了,當複製代碼tanQ,但在我的項目有 '':d tanQ –