<!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%3DAU%26CaseNo2%3D1%26FileType%3D2%26Lang%3DC%22&format=json&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].車站緯度, temp[index].車站經度), title:temp[index].車站中文名稱 }); 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://api.jquery.com/jquery.getjson/
http://developer.yahoo.com/yql/console/#h=desc+yql.env
http://data.kaohsiung.gov.tw/Opendata/DetailList.aspx?CaseNo1=AU&CaseNo2=1&Lang=C
http://data.kaohsiung.gov.tw/Opendata/DownLoad.aspx?Type=2&CaseNo1=AU&CaseNo2=1&FileType=2&Lang=C
https://developers.google.com/maps/documentation/javascript/examples/marker-simple