百度地图在调用ajax的时候,拿到了返回的数据以后为什么没办法在地图上显示出来,各位大神帮忙看看代码
月上谷 2017-09-06 05:07:07 <!DOCTYPE html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
body, html,#allmap {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
#l-map{height:500px;width:100%;}
</style>
<script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=2125f92498eb27421b044033f96c2725"></script>
<title>b页面</title>
</head>
<body>
<div id="l-map"></div>
<div id="r-result">
<input type="button" onclick="showOver()" value="显示" />
<input type="button" onclick="hideOver()" value="隐藏" />
</div>
<script src="jquery-3.2.1.min.js"></script>
<script type="text/javascript">
$(function(){
$.ajax({
type: 'get',
data: '',
url: 'http://119.29.218.203:20770/GetLagLat.asmx/GetTrackRT',
dataType: 'json',
success:function(res){
for(var i = 0;i<res.length;i++){
var item = res[i];
var VehId = item.VehId;
var VehNo = item.VehNo;
var Latitude = item.Latitude;
var Longitude = item.Longitude;
}
}
})
})
// 百度地图API功能
var map = new BMap.Map("l-map");
var point = new BMap.Point(Latitude, Longitude);
map.centerAndZoom(point, 15);
var marker = new BMap.Marker(new BMap.Point(Latitude, Longitude)); // 创建标注
map.addOverlay(marker); // 将标注添加到地图中
var polyline = new BMap.Polyline([
new BMap.Point(116.399, 39.910),
new BMap.Point(116.405, 39.920),
new BMap.Point(116.425, 39.900)
], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});
map.addOverlay(polyline); //增加折线
var circle = new BMap.Circle(point,500);
map.addOverlay(circle); //增加圆
hideOver();
function showOver(){
marker.show(); polyline.show(); circle.show();
}
function hideOver(){
marker.hide(); polyline.hide(); circle.hide();
}
</script>
</body>
</html>