对于相应的id,我希望标记指向该id的数据库地址。我能怎么做?我在哪里可以获得代码?我正在使用JS,Asp.Net,Sql server
答案 0 :(得分:0)
这很简单,你必须创建一个数据库表,其中包括你的纬度和经度..如果你需要一个简单的英文地址,那么你必须在存储地址后使用Google Geolocation API, 然后对于位置表中的每个条目执行以下操作 在.cs
public StringBuilder locs = new StringBuilder(); //globalVariable
StringBuilder sb = new StringBuilder();
foreach (Location l in loc)
{
longitude = l.Yaxis; //where Yaxis is a variable in class Location to store longitude
lattudei = l.Xaxis; //where Xaxis is a variable in class Location to store Latitutde
sb.Append(string.Format(
"['{2}','{0}','{1}','../Img/Icons/Vehicles/icon_{2}.png'],",
lati, lon, imgurl);
}
locs.Append(sb.ToString());
<强>的.aspx 强>
<script>
var map;
map = new google.maps.Map(document.getElementById('map'), {
zoom: 5,
minZoom: 4,
maxZoom: 8,
center: new google.maps.LatLng(30.03105543, -39.44091797),
});
var locations = [<%=locs %> ];
var markers=[];
for (i = 0; i < locations.length; i++) {
var marker = new google.maps.Marker({
position: new google.maps.LatLng(locations[i][1], locations[i][2]),
map: map,
icon: new google.maps.MarkerImage(locations[i][3] + "?" + new Date().getTime(),
null, null, null, new google.maps.Size(40,15)),
id: locations[i][0],
});
markers.push(marker);
</script>