-1
JSONデータをajax呼び出しを使用して変数に格納します。どのようにajax呼び出しを記述し、JSONデータ値を変数に保存してGoogleマップのデータを表示するか。 JSONのDustValue
が必要で、Google Maps jsの変数に割り当てる必要があります。ajax呼び出しを使用してvaribeにjsonデータを格納する方法
<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"}}