Web Page สร้างเว็บเพจ html5 javascript แสดงแผนที่ โดยดึงพิกัดจาก Ms sql มาแสดงทั้งหมด พอดีไม่ค่อยเก่ง Javascript
มีสคริปเชื่อมดาต้าเบส แต่ไม่รู้จะทำยังไงให้แสดงบนแผนที่อ่าคะ
Code (JavaScript)
<script>
var objConnection = new ActiveXObject("adodb.connection");
var strConn = "driver={sql server};server=SERVER_NAME;database=DATABASE_NAME;uid=USERNAME;password=PASSWORD";
objConnection.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var strQuery = "SELECT LocalDesc,Latitude,Longitude FROM dbo.Branch";
rs.Open(strQuery, objConnection);
rs.MoveFirst();
while (!rs.EOF) {
name = rs.fields(0);
lat = rs.fields(1);
lng = rs.fields(2);
document.write("addmarker(" + name +","+ lat +","+ lng + ")");
rs.movenext();
}
</script>
Code
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<!-- TemplateBeginEditable name="doctitle" -->
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 400px; width: 500px;">
</div>
<script type="text/javascript">
var locations = [
['Bondi Beach', -33.890542, 151.274856, 4],
['Coogee Beach', -33.923036, 151.259052, 5],
['Cronulla Beach', -34.028249, 151.157507, 3],
['Manly Beach', -33.80010128657071, 151.28747820854187, 2],
['Maroubra Beach', -33.950198, 151.259302, 1]
];
var map = new google.maps.Map(document.getElementById('map'), {
zoom: 10,
center: new google.maps.LatLng(-33.92, 151.25),
mapTypeId: google.maps.MapTypeId.ROADMAP
});
var infowindow = new google.maps.InfoWindow();
var marker, i;
for (i = 0; i < locations.length; i++) {
marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map
});
google.maps.event.addListener(marker, 'click', (function(marker, i) {
return function() {
infowindow.setContent(locations[i][0]);
infowindow.open(map, marker);
}
})(marker, i));
}
</script>
</body>
</html>
Tag : Ms SQL Server 2005, Ms SQL Server 2008, Ms SQL Server 2012, HTML/CSS, JavaScript
<script>
var objConnection = new ActiveXObject("adodb.connection");
var strConn = "driver={sql server};server=SERVER_NAME;database=DATABASE_NAME;uid=USERNAME;password=PASSWORD";
objConnection.Open(strConn);
var rs = new ActiveXObject("ADODB.Recordset");
var strQuery = "SELECT LocalDesc,Latitude,Longitude FROM dbo.Branch";
rs.Open(strQuery, objConnection);
rs.MoveFirst();
while (!rs.EOF) {
name = rs.fields(0);
lat = rs.fields(1);
lng = rs.fields(2);
document.write("addmarker(" + name +","+ lat +","+ lng + ")");
rs.movenext();
}
</script>