【发布时间】:2016-08-30 06:59:15
【问题描述】:
我希望使用 ajax 调用将 JSON 数据存储在变量中。如何编写 ajax 调用并将 JSON 数据值保存在变量中以在 Google 地图中显示数据。需要来自 JSON 的DustValue,并且应该在 Google Maps js 的变量中分配。
<head>
<script src="https://maps.googleapis.com/maps/api/js?key=AIzaSyCLi6lY_WbRa9mkWKc" type="text/javascript"></script>
<script>
var myCenter = new google.maps.LatLng(22.8046, 86.2029);
function initialize()
{
var mapProp = {
center:myCenter,
zoom:17,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap"),mapProp);
var DustValue=23;// ajax call.. $.ajax({url: 'http://xyz.in/dust/get'......
var dustbinstatus='';
if(DustValue<50){
dustbinstatus = 'img/dustbinempty.png';
} else if(DustValue>50 && DustValue<90){
dustbinstatus = 'img/dustbinfull.png';
} else if(DustValue>90){
dustbinstatus = '3.jpg';
}
var marker=new google.maps.Marker({
position:myCenter,
icon: v_icon
});
marker.setMap(map);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<body>
<div id="googleMap" style="width:1580px;height:780px;"></div>
</body>
样本数据:
{"success":true,"sensorsdata":{"WaterTemperature":null,"DustValue":23.00,"DOValue":null,"CurrentTime":"29-August-2016 02:59:AM"}}
【问题讨论】:
标签: javascript json ajax google-maps asp.net-ajax