我在Microsoft Access数据库中有纬度(纬度)和经度(lng),并且我试图循环GridView以在地图上显示点位置,但无论我在做什么它都不起作用。这就像我无法循环GridView来获取我的数据,但如果我使用xml它就可以工作。
这是我的代码:
<script type="text/javascript">
//<![CDATA[
if (GBrowserIsCompatible()) {
// this variable will collect the html which will eventualkly be placed in the side_bar
var side_bar_html = "";
// arrays to hold copies of the markers used by the side_bar
// because the function closure trick doesnt work there
var gmarkers = [];
// A function to create the marker and set up the event window
function createMarker(point, name, html) {
var marker = new GMarker(point);
GEvent.addListener(marker, "click", function () {
marker.openInfoWindowHtml(html);
});
// save the info we need to use later for the side_bar
gmarkers.push(marker);
// add a line to the side_bar html
side_bar_html += '<a href="javascript:myclick(' + (gmarkers.length - 1) + ')">' + name + '<\/a><br>';
return marker;
}
// This function picks up the click and opens the corresponding info window
function myclick(i) {
GEvent.trigger(gmarkers[i], "click");
}
// create the map
var map = new GMap2(document.getElementById("map"));
map.addControl(new GLargeMapControl());
map.addControl(new GMapTypeControl());
map.setCenter(new GLatLng(43.907787, -79.359741), 9);
var markers = document.getElementById('<%= GridView1.ClientID %>');
for (var row = 1; row < markers.rows.length; row++) {
for (var col = 0; col < markers.rows[row].cells.length; col++) {
if (col == 0) {
if (document.all)
var label = new markers.rows[row].cells[col].innerText;
else
var label = new markers.rows[row].cells[col].textContent;
}
if (col == 2) {
if (document.all)
var lat = new markers.rows[row].cells[col].innerText;
else
var lat = new parseFloat(markers.rows[row].cells[col].textContent);
}
if (col == 3) {
if (document.all)
var lng = new parseFloat(markers.rows[row].cells[col].innerText);
else
var lng = new parseFloat(markers.rows[row].cells[col].textContent);
}
else if (document.all) {
}
var str = new markers.rows[row].cells[col].innerText;
var point = new GLatLng(lat, lng);
var html = terrnaam + ' ' + address;
var marker = createMarker(point, label, html);
map.addOverlay(marker);
document.getElementById("side_bar").innerHTML = side_bar_html;
}
}
}
else {
alert("Sorry, the Google Maps API is not compatible with this browser");
}
//]]>
</script>