Add or Show mark on Google Maps in asp.net website
Show mark on Google Maps in asp.net website:
In this post we try
to describe how to show or add multiple markers to Google maps V3 from Data Table in asp.net website using JavaScript or JavaScript Show multiple markers in
Google maps using Data Table in asp.net. we Consider other google map related post in this tutorial Asp.net Show (add) Markers on Google Map. and Integrate or show Google Maps in asp.net web site
Create DataTable For binding google Mape:
For this First we create a Dynamic data table C# code with
some fields.
DataTable dt = new
DataTable();
dt.Columns.AddRange(new DataColumn[3] { new
DataColumn("City"),
new DataColumn("Lattiude"), new
DataColumn("Longitude")
});
dt.Rows.Add("City1", "12.897400", "80.288000");
dt.Rows.Add("City2","17.266700", "78.530200");
dt.Rows.Add("City3","12.897400", "77.519500");
Now we make a page in which we use google Map by google API:
Use this link on page in header section.
JavaScript Function for Creating Mark on Map:
function(marker, data) {
// Attaching a click event to the
current marker
google.maps.event.addListener(marker, "click", function(e)
{
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
}
Create markers to Google Maps in asp.net website:
<%@ Page
Language="C#"
AutoEventWireup="true"
CodeFile="Map.aspx.cs"
Inherits="_Default"
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD
XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title> Google Maps in asp.net website</title>
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0; padding: 0 }
#map_canvas { height:
100% }
</style>
<script type="text/javascript" src
= "https://maps.googleapis.com/maps/api/js?key=AIzaSyC6v5-2uaq_wusHDktM9ILcqIrlPtnZgEk&sensor=false">
</script>
<script type="text/javascript">
function initialize()
{
var markers = JSON.parse('<%=ConvertDataTabletoString()
%>');
var mapOptions = {
center: new
google.maps.LatLng(markers[0].lat, markers[0].lng),zoom: 5,mapTypeId:
google.maps.MapTypeId.ROADMAP
};
var infoWindow = new
google.maps.InfoWindow();
var map = new
google.maps.Map(document.getElementById("map_canvas"),
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) {
// Attaching a click event to the
current marker
google.maps.event.addListener(marker, "click", function(e)
{
infoWindow.setContent(data.description);
infoWindow.open(map, marker);
});
})(marker, data);
}
}
</script>
</head>
<body onload="initialize()">
<form id="form1" runat="server">
<div id="map_canvas" style="width: 100%; height: 600px"></div>
</form>
</body>
</html>
C# code for Create markers to Google:
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
public partial class _Default :
System.Web.UI.Page
{
protected void
Page_Load(object sender, EventArgs e)
{
}
// convert in jsonstring
public string
ConvertDataTabletoString()
{
DataTable dt = new
DataTable();
dt.Columns.AddRange(new DataColumn[2] { new
DataColumn("City"),
new DataColumn("Lattiude"), new
DataColumn("Longitude")
});
dt.Rows.Add("City1", "12.897400", "80.288000");
dt.Rows.Add("City2","17.266700", "78.530200");
System.Web.Script.Serialization.JavaScriptSerializer
serializer = new
System.Web.Script.Serialization.JavaScriptSerializer();
List<Dictionary<string, object>>
rows = new List<Dictionary<string,
object>>();
Dictionary<string, object> row;
foreach (DataRow
dr in dt.Rows)
{
row = new Dictionary<string, object>();
foreach (DataColumn
col in dt.Columns)
{
row.Add(col.ColumnName,
dr[col]);
}
rows.Add(row);
}
return serializer.Serialize(rows);
}
}
Other ASP.NET Programming Post:
- Hide-radio-buttons-in-javascript
- Data type in c with asp.net.
- Web services in asp.
- Dynamically creating aspx page,
- Get the current page url by C#
- jQuery modal dialog with postbacks
- How-to-set-current-data-into-asp-text.
- C# Variables,How to declare in C#:
- C# language Program Structure
- Check box in asp Dropdown List.
- Drop Down List control of asp.net
- Select option to the user from many items.
- DropDown List in asp.net Programming,
- What keyword,How many keywords in C#
- Add ListItem in DropDownList asp.net c# Example
- Using jQuery change Background color of DIV
- JQuery Change Div Background Color Randomly
- Get selected radio button values using JQuery.
- How do you do html text encodes using JavaScript
- Limit Number of Characters in a TextArea using jQuery
- Characters inTextbox in asp.netusing jquery:
- Drag and Drop Sortable Lists using jQueryUI
- jquery tooltip with css in asp.net web page
- Ajax ColorPickerExtender in ASP.NET Example
- What is the Ajax colorpicker,How to use Ajax colorpicker
- JQuery UI Datepicker (Calendar) with asp.net textbox
- Adding or binding tooltip in each item of dropdownlist
- jquery disable or Enable submit button after validation
- Example of Adding ToolTip for each Dropdown List Item in C#
- Displaying the textbox value in javascript Messagebox
- Enable Disable Submit Button using jQuery
- jquery disable or Enable submit button after validation
- What is ASP.NET FRAMEWORK PART 1 Programming
- Display selected Date from data base into asp.net calendar
- How to create Line chart:,How to Make Data Table By C# code:
- Example of C# for Bind Data to asp.net Textbox inside gridview control
- Bind Data to asp.net textbox control in inside of gridview Using C# Example
- Example of Crystal report(Crystal_report_in asp.net programming )
- SQL Helper Class, Example of how to add captcha in Asp.net using C#
- Sql Query for asp.net Programming , How to create graph in asp.net:
Comments
Post a Comment