源代碼:
- <head runat="server">
- <title>Untitled Page</title>
- <script src="<%=mapKey%>" type="text/javascript"></script>
- <script language="javascript" type="text/javascript">
- function showAddress() {
- var map = new GMap2(document.getElementById("mapPanel"));
- var geocoder = new GClientGeocoder();
- var address=document.getElementById("Hidden1").value;
- geocoder.getLatLng(address,function(point) {
- if (!point)
- {
- alert(address + " not found");
- }
- else
- {
- map.setCenter(point, 13);
- var marker = new GMarker(point);
- map.addOverlay(marker);
- marker.openInfoWindowHtml(address);
- alert(point);
- } } );}
- </script>
- </head>
- <body οnlοad="showAddress();" οnunlοad="GUnload()">
- <form id="Form2" runat="server" action="">
- <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
- <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
- <input id="Hidden1" runat="server" type="hidden" />
- <div id="mapPanel" style="width: 500px; height: 300px;">
- </div>
- </form>
- </body>
- </html>
- CS代碼:
- protected void Button1_Click(object sender, EventArgs e)
- {
- Hidden1.Value = TextBox1.Text.Trim();
- }
注:mapKey請到http://code.google.com/intl/zh-CN/apis/maps/signup.html進行申請