[英]Reading from a database of locations
I have this scenario, can anybody fill the gaps for me? 我有这种情况,有人可以为我填补空白吗? Its like this: 就像这样:
Database Table Maps' fields: 数据库表映射的字段:
Map_ID, Coordinates, MarkerTitle, MarkerField. Map_ID,座标,MarkerTitle,MarkerField。
Code Behind: 背后的代码:
Dim myTableAdapter As New myDatasetTableAdapters.tblMapsTableAdapters
Dim myTable As myDataset.tblMapsDataTable = myTableAdapter.GetAllMaps()
Right now, I am assigning one value at a time to be able to show one googleMap in my page, simply by having Friend Variables and in codebehind which gets their values on PageLoad and I declared variables with the same name in my script that shows the maps, its like: 现在,我一次分配一个值即可在我的页面中显示一个googleMap,只需在Friend Variables和codebehind中将它们的值显示在PageLoad上,然后在脚本中声明具有相同名称的变量即可显示地图,就像:
Code Behind: 背后的代码:
Friend coordinates As String
Friend zoom As String
Friend maptitle As String
Friend text As String
Script: 脚本:
<script type="text/javascript">
function load() {
var map = new GMap2(document.getElementById("map"));
var marker1 = new GMarker(new GLatLng(<%=coordinates%>));
var html1="<%=maptitle%><br/>" + "<%=text%>";
map.setCenter(new GLatLng(<%=coordinates%>), 5);
map.setMapType(G_HYBRID_MAP);
map.addOverlay(marker1);
map.addControl(new GLargeMapControl());
map.addControl(new GScaleControl());
map.addControl(new GMapTypeControl());
marker.openInfoWindowHtml(html1);
}
</script>
How can I go from the above procedure to something like: passing a whole tableOfMaps to the JavaScript or reading this data their (retrieving database information from within the JavaScript side) and then iterating like this: 我如何从上述过程转到类似的过程:将整个tableOfMaps传递给JavaScript或读取其数据(从JavaScript端检索数据库信息),然后进行如下迭代:
For Each map In MapsTable
{
var marker1 = new GMarker(new GLatLng(<%=coordinates%>));
var html1="<%=maptitle%><br/>" + "<%=text%>";
map.addOverlay(marker1);
marker.openInfoWindowHtml(html1);
}
I know this is too much to ask, so help will be deeply appreciated... 我知道这个问题太多了,因此我们将不胜感激帮助。
I'm going to use jQuery to simplify things, hope that's OK... 我将使用jQuery简化事情,希望可以...
Perform the database look-ups on the server-side, and emit data into the HTML. 在服务器端执行数据库查找,并将数据发送到HTML。 You should be looking to produce something like this: 您应该希望产生以下内容:
<div id="maps-table">
<div class="map-entry">
<span class="map-title">Title 1</span>
<span class="map-text">Text 1</span>
<span class="map-coordinates">Coordinates 1</span>
</div>
<div class="map-entry">
<span class="map-title">Title 2</span>
<span class="map-text">Text 2</span>
<span class="map-coordinates">Coordinates 2</span>
</div>
...
</div>
If you're using something like ASP.NET you can use an asp:Repeater. 如果您使用的是ASP.NET之类的东西,则可以使用asp:Repeater。
Once you have the data rendered in your HTML, you can query and iterate over it: 用HTML呈现数据后,就可以查询和遍历它:
$('#maps-table .map-entry').each(function() {
var title = $(this).find('.map-title').text();
var text = $(this).find('.map-text').text();
var coordinates = $(this).find('.map-coordinates').text();
// Add map markers here, eg:
var marker = new GMarker(new GLatLng(coordinates));
var html = title + "<br/>" + text;
map.addOverlay(marker);
marker.openInfoWindowHtml(html);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.