Today, i'll show you how to integrate google maps with asp.net page.
The first step before using Google Maps is to register for a key with Google
(www.google.com/apis/maps/signup.html).
This is absolutely free and hardly takes a few minutes.
Add a DIV tag to the .aspx page.
<div id="map" style="width: 450px; height: 400px; border: 1px solid #979797;"></div>
In the code-behind file, add the following code to the Page_Load event handler
protected void Page_Load(object sender, EventArgs e) {
if (!(this.Page.ClientScript.IsClientScriptBlockRegistered("onload"))) {
//Replace your address here that you want in google map
string Address= "Torono, on";
//Replace you google API key here
string GAPIKey = "xxxxxxxxxxxxxxxxxx";
StringBuilder sb = new StringBuilder();
sb.AppendFormat("<script src=\"http://maps.google.com/maps?file=api&v=2&key={0}\" type=\"text/javascript\"></script>", GAPIKey);
sb.Append("<script type=\"text/javascript\" language=\"javascript\">var map = null;var geocoder = null;");
sb.Append(" window.onload = function(){if (GBrowserIsCompatible()){map = new GMap2(document.getElementById(\"");
sb.AppendFormat("{0}\"));", "map");
sb.AppendLine("map.addControl(new GLargeMapControl());map.addControl(new GMapTypeControl());geocoder = new GClientGeocoder();");
sb.Append("if (geocoder){geocoder.getLatLng(");
sb.AppendFormat("'{0}'", Address);
sb.Append(",function(point) {if (point){map.setCenter(point, 13, G_NORMAL_MAP);");
sb.Append(" var marker = new GMarker(point);map.addOverlay(marker);");
sb.AppendFormat("marker.openInfoWindowHtml('{0}');", Address);
sb.Append("}});}}}</script>");
this.Page.ClientScript.RegisterStartupScript(this.Page.GetType(), "onload", sb.ToString());
} }
Please feel free to leave any comments.