http://51aspx.com/CV/GoogleMapControl/
今天在51aspx看到這個控制項,挺不錯,簡單用一下:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SimpleMapWithNoBubble.aspx.cs" Inherits="Samples_SimpleMap" %></p><p><%@ Register Src="~/GoogleMapForASPNet.ascx" TagName="GoogleMapForASPNet" TagPrefix="uc1" %></p><p><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"></p><p><html xmlns="http://www.w3.org/1999/xhtml" ><br /><head runat="server"><br /> <title>Simple Google Map</title><br /></head><br /><body><br /> <h3><a href="Default.aspx" mce_href="Default.aspx">Back</a></h3><br /> <form id="form1" runat="server"><br /> <h3>Simple Google Map</h3><br /> <div><br /> <uc1:GoogleMapForASPNet ID="GoogleMapForASPNet1" runat="server" /><br /> </div><br /> </form><br /></body><br /></html><br />
後台:
using System;<br />using System.Data;<br />using System.Configuration;<br />using System.Collections;<br />using System.Web;<br />using System.Web.Security;<br />using System.Web.UI;<br />using System.Web.UI.WebControls;<br />using System.Web.UI.WebControls.WebParts;<br />using System.Web.UI.HtmlControls;</p><p>public partial class Samples_SimpleMap : System.Web.UI.Page<br />{<br /> protected void Page_Load(object sender, EventArgs e)<br /> {<br /> //You must specify Google Map API Key for this component. You can obtain this key from http://code.google.com/apis/maps/signup.html<br /> //For samples to run properly, set GoogleAPIKey in Web.Config file.<br /> GoogleMapForASPNet1.GoogleMapObject.APIKey = ConfigurationManager.AppSettings["GoogleAPIKey"]; </p><p> //Specify width and height for map. You can specify either in pixels or in percentage relative to it's container.<br /> GoogleMapForASPNet1.GoogleMapObject.Width = "800px"; // You can also specify percentage(e.g. 80%) here<br /> GoogleMapForASPNet1.GoogleMapObject.Height = "600px";</p><p> //Specify initial Zoom level.<br /> GoogleMapForASPNet1.GoogleMapObject.ZoomLevel = 14;</p><p> //Specify Center Point for map. Map will be centered on this point.<br /> GoogleMapForASPNet1.GoogleMapObject.CenterPoint = new GooglePoint("1", 43.66619, -79.44268);</p><p> //Add pushpins for map.<br /> //This should be done with intialization of GooglePoint class.<br /> //In constructor of GooglePoint, First argument is ID of this pushpin. It must be unique for each pin. Type is string.<br /> //Second and third arguments are latitude and longitude.<br /> GoogleMapForASPNet1.GoogleMapObject.Points.Add(new GooglePoint("1", 43.65669, -79.45278));<br /> GoogleMapForASPNet1.GoogleMapObject.Points.Add(new GooglePoint("2", 43.66619, -79.44268));<br /> GoogleMapForASPNet1.GoogleMapObject.Points.Add(new GooglePoint("3", 43.67689, -79.43270));</p><p> GooglePoint GP = new GooglePoint();<br /> GP.ID = "1";<br /> GP.Latitude = 43.65669;<br /> GP.Longitude = -79.43270;<br /> GoogleMapForASPNet1.GoogleMapObject.Points.Add(GP);<br /> }<br />}<br />