2014/02/26

透過YQL取得高雄市私立課後托育中心並繪製到Google Map

<!DOCTYPE html>
<html>
<head>
 <meta charset="utf8">
 <title>OpenData Demo1 by C.Y. Fang</title>
 <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>
 <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
 <script type="text/javascript">
  function initialize() {
   var temp;
   var mapOptions = {
     zoom: 12,
     center: new google.maps.LatLng(22.631386, 120.301951),
     mapTypeId: google.maps.MapTypeId.ROADMAP,
    }
   var map = new google.maps.Map(document.getElementById("map"), mapOptions);
   var url = "http://query.yahooapis.com/v1/public/yql?q=SELECT%20*%20FROM%20html%20WHERE%20url%3D%22http%3A%2F%2Fdata.kaohsiung.gov.tw%2FOpendata%2FDownLoad.aspx%3FType%3D2%26CaseNo1%3DAE%26CaseNo2%3D12%26FileType%3D1%26Lang%3DC%22&format=json&diagnostics=true&callback=?";
 
   $.getJSON(url, function(data){
    temp = JSON.parse(data.query.results.body.p);
    
    if(temp){
     var m_length = temp.length;
     for(var index=0; index<m_length;index++){
 
      var marker = new google.maps.Marker({
       position: new google.maps.LatLng(temp[index].lat, temp[index].lng),
       title:temp[index].org_Text + "\n" 
            + temp[index].informaddress + "\n"
            + temp[index].servTime + "\n"
            + temp[index].informtel
      });

      marker.setMap(map);
     }
    }

   });
  }
 </script>
 <style type="text/css">
  html { height: 100% }
  body { height: 100%; margin: 0; padding: 0 }
  #map { height: 95% ; width: 100% }
 
    </style>
</head>
<body onload="initialize()">
 <div id="map"></div>
</body>
</html>







參考資料:
http://data.kaohsiung.gov.tw/Opendata/DetailList.aspx?CaseNo1=AE&CaseNo2=12&Lang=C
http://data.kaohsiung.gov.tw/Opendata/DownLoad.aspx?Type=2&CaseNo1=AE&CaseNo2=12&FileType=1&Lang=C