<script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
<script type="text/javascript">
var markers = [
<asp:Repeater ID="rptMarkers" runat="server">
<ItemTemplate>
{
"title": '<%# Eval("title") %>',
"lat": '<%# Eval("lat") %>',
"lng": '<%# Eval("lng") %>',
"description": '<b><%# Eval("title") %></b> <br><%# Eval("address") %>'
}
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
];
</script>
<script type="text/javascript">
window.onload = function () {
Dataload();
}
function Dataload() {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 13,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
<script type="text/javascript">
var markers = [
<asp:Repeater ID="rptMarkers" runat="server">
<ItemTemplate>
{
"title": '<%# Eval("title") %>',
"lat": '<%# Eval("lat") %>',
"lng": '<%# Eval("lng") %>',
"description": '<b><%# Eval("title") %></b> <br><%# Eval("address") %>'
}
</ItemTemplate>
<SeparatorTemplate>
,
</SeparatorTemplate>
</asp:Repeater>
];
</script>
<script type="text/javascript">
window.onload = function () {
Dataload();
}
function Dataload() {
var mapOptions = {
center: new google.maps.LatLng(markers[0].lat, markers[0].lng),
zoom: 13,
disableDefaultUI: true,
mapTypeId: google.maps.MapTypeId.ROADMAP
};
var infoWindow = new google.maps.InfoWindow();
var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
for (i = 0; i < markers.length; i++) {
var data = markers[i]
var myLatlng = new google.maps.LatLng(data.lat, data.lng);
var marker = new google.maps.Marker({
position: myLatlng,
map: map,
title: data.title
});
(function (marker, data) {
google.maps.event.addListener(marker, "click", function (e) {
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
C#.NET:
protected void page_load(object sender, EventArgs e) { if (!IsPostBack) { DataColumn dValue = new DataColumn(); DataColumn dlat = new DataColumn(); DataColumn dlng = new DataColumn(); DataColumn dadd = new DataColumn(); dValue.ColumnName = "title"; dValue.DataType = Type.GetType("System.String"); dlat.ColumnName = "lat"; dlat.DataType = Type.GetType("System.String"); dlng.ColumnName = "lng"; dlng.DataType = Type.GetType("System.String"); dadd.ColumnName = "address"; dadd.DataType = Type.GetType("System.String"); // Add these DataColumns into the DataTable dtSearchResults.Columns.Add(dadd); dtSearchResults.Columns.Add(dValue); dtSearchResults.Columns.Add(dlat); dtSearchResults.Columns.Add(dlng); DataRow dr = dtSearchResults.NewRow(); dr["title"] = "k R puram"; dr["lat"] = "13.0126101"; dr["lng"] = "77.7165925"; dr["address"] = "33/1, k r puram"; dtSearchResults.Rows.Add(dr); DataRow dr1 = dtSearchResults.NewRow(); dr["title"] = "Uppal"; dr["lat"] = "17.4018092"; dr["lng"] = "78.5601892"; dr["address"] = "33/1, Uppal"; dtSearchResults.Rows.Add(dr1); DataRow dr2 = dtSearchResults.NewRow(); rptMarkers.DataSource = dtSearchResults; rptMarkers.DataBind(); } }
VB.NET:
Protected Sub page_load(sender As Object, e As EventArgs) If Not IsPostBack Then Dim dValue As New DataColumn() Dim dlat As New DataColumn() Dim dlng As New DataColumn() Dim dadd As New DataColumn() dValue.ColumnName = "title" dValue.DataType = Type.[GetType]("System.String") dlat.ColumnName = "lat" dlat.DataType = Type.[GetType]("System.String") dlng.ColumnName = "lng" dlng.DataType = Type.[GetType]("System.String") dadd.ColumnName = "address" dadd.DataType = Type.[GetType]("System.String") ' Add these DataColumns into the DataTable dtSearchResults.Columns.Add(dadd) dtSearchResults.Columns.Add(dValue) dtSearchResults.Columns.Add(dlat) dtSearchResults.Columns.Add(dlng) Dim dr As DataRow = dtSearchResults.NewRow() dr("title") = "k R puram" dr("lat") = "13.0126101" dr("lng") = "77.7165925" dr("address") = "33/1, k r puram" dtSearchResults.Rows.Add(dr) Dim dr1 As DataRow = dtSearchResults.NewRow() dr("title") = "Uppal" dr("lat") = "17.4018092" dr("lng") = "78.5601892" dr("address") = "33/1, Uppal" dtSearchResults.Rows.Add(dr1) Dim dr2 As DataRow = dtSearchResults.NewRow() rptMarkers.DataSource = dtSearchResults rptMarkers.DataBind() End If End Sub
No comments:
Post a Comment