|
|
|
ช่วยด้วยค่ะ google map มันจิ้มไม่ลง Please please !! |
|
|
|
|
|
|
|
Google Map
คือว่า พอsearch เจอ แต่เราจะเอาข้างๆ มันจิ้มไม่ลง ไม่รู้ว่าเปนอะไร หรือว่าเรียกใช้จาก master page งงๆ แต่ถ้าทำแบบธรรมดามันจิ้มลงค่ะ ทั้งๆที่ โค้ดแทบจะเหมือนกันทุกอย่าง
### 1 ###
โค้ดกะรูปนี้ คือ page ที่สร้าง โดยมี master page ครอบ ค่ะ
Code (C#)
<%@ Page Title="" Language="C#" MasterPageFile="~/SiteMaster2.Master" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="DDProperty.WebForm1" %>
<%@ Register assembly="GMaps" namespace="Subgurim.Controles" tagprefix="cc1" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAXr8HWGsn5O2iz7zvk_gkoRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSpnGkJL5-RE7iMmVQjd8n5AKEJiQ" type="text/javascript">
</script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAXr8HWGsn5O2iz7zvk_gkoRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSpnGkJL5-RE7iMmVQjd8n5AKEJiQ" type="text/javascript">
</script>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>สาทร</asp:ListItem>
<asp:ListItem>รามคำแหง</asp:ListItem>
</asp:DropDownList>
<cc1:GMap ID="GMap1" runat="server" />
<asp:Button ID="btnSave" runat="server" Text="Save New Location"
onclick="btnSave_Click" />
<asp:HiddenField ID="hidLat" runat="server" />
<asp:HiddenField ID="Lat" runat="server" />
<asp:HiddenField ID="Long" runat="server" />
<asp:HiddenField ID="hidLng" runat="server" />
</asp:Content>
protected Subgurim.Controles.GMarker oMarker;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
Lat.Value = hidLat.Value;
Long.Value = hidLng.Value;
GMap1.resetMarkers();
GMap1.resetListeners();
AddMarker(Convert.ToDouble(hidLat.Value), Convert.ToDouble(this.hidLng.Value));
}
protected void btnLocate_Click(object sender, EventArgs e)
{
Subgurim.Controles.GeoCode GeoCode = default(Subgurim.Controles.GeoCode);
GeoCode = GMap1.geoCodeRequest(DropDownList1.SelectedValue);
if (GeoCode.valid == true)
{
Lat.Value = Convert.ToString(GeoCode.Placemark.coordinates.lat);
Long.Value = Convert.ToString(GeoCode.Placemark.coordinates.lng);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
AddMarker(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
}
else
{
Msg("Unable to find that location.");
}
}
private void AddMarker(double dLat, double dLong)
{
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(dLat, dLong);
Subgurim.Controles.GMarkerOptions oOption = new Subgurim.Controles.GMarkerOptions();
oOption.draggable = true;
GMap1.resetMarkers();
GMap1.resetListeners();
oMarker = new Subgurim.Controles.GMarker(gLatLng, oOption);
GMap1.addGMarker(oMarker);
GMap1.addListener(new Subgurim.Controles.GListener(oMarker.ID, Subgurim.Controles.GListener.Event.dragend, "function(){ document.getElementById('hidLat').value=" + oMarker.ID + ".getPoint().lat();document.getElementById('hidLng').value=" + oMarker.ID + ".getPoint().lng() }"));
}
private void Msg(string sText)
{
//Page.ClientScript.RegisterClientScriptBlock(GetType(String), "msg", "<script>Alert('" & sText & "');</script>")
Response.Write("<script type='text/javascript'>alert('" + sText + "');</script>");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Subgurim.Controles.GeoCode GeoCode = default(Subgurim.Controles.GeoCode);
GeoCode = GMap1.geoCodeRequest(DropDownList1.SelectedValue);
if (GeoCode.valid == true)
{
Lat.Value = Convert.ToString(GeoCode.Placemark.coordinates.lat);
Long.Value = Convert.ToString(GeoCode.Placemark.coordinates.lng);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
AddMarker(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
}
else
{
Msg("Unable to find that location.");
}
}
### 2 ###
โค้ดกะรูปนี้ คือ สร้าง page ธรรมดาๆเลย ขยับแล้วจิ้มลง อ่านค่าใหม่ได้
Code (C#)
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="googleMap._Default" %>
<%@ Register Assembly="GMaps" Namespace="Subgurim.Controles" TagPrefix="cc1" %>
<!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 runat="server">
<title></title>
<style type="text/css">
.style1
{
width: 98px;
}
</style>
<script src="http://maps.google.com/maps?file=api&v=2&sensor=true_or_false&key=ABQIAAAAXr8HWGsn5O2iz7zvk_gkoRT2yXp_ZAY8_ufC3CFXhHIE1NvwkxSpnGkJL5-RE7iMmVQjd8n5AKEJiQ" type="text/javascript">
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:HiddenField ID="hidLat" runat="server" />
<asp:HiddenField ID="Lat" runat="server" />
<asp:HiddenField ID="Long" runat="server" />
<asp:HiddenField ID="hidLng" runat="server" />
<table>
<tr>
<td class="style1">ค้นหาสถานที่</td><td colspan=2>
<asp:TextBox ID="txtLocation" runat="server" Width="368px"></asp:TextBox></td>
</tr>
<tr>
<td class="style1"></td><td colspan="2"><asp:Button ID="btnLocate" runat="server"
Text="Search" onclick="btnLocate_Click" /></td>
</tr>
<tr>
<td class="style1"> </td><td>ละติจูด: <asp:TextBox ID="txtLat" runat="server"></asp:TextBox></td><td>
ลองติจูด: <asp:TextBox ID="txtLong" runat="server"></asp:TextBox></td>
</tr>
<tr>
<td class="style1"> </td><td>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"
onselectedindexchanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem>สาทร</asp:ListItem>
<asp:ListItem>รามคำแหง</asp:ListItem>
</asp:DropDownList>
</td><td>
</td>
</tr>
<tr>
<td colspan="3">
<cc1:GMap ID="GMap1" runat="server" />
</td>
</tr>
<tr>
<td colspan="3"><asp:Button ID="btnSave" runat="server" Text="Save New Location"
onclick="btnSave_Click" />
</td>
</tr>
</table>
</form>
</body>
</html>
protected Subgurim.Controles.GMarker oMarker;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSave_Click(object sender, EventArgs e)
{
txtLat.Text = hidLat.Value;
Long.Value = hidLng.Value;
GMap1.resetMarkers();
GMap1.resetListeners();
AddMarker(Convert.ToDouble(hidLat.Value), Convert.ToDouble(this.hidLng.Value));
}
protected void btnLocate_Click(object sender, EventArgs e)
{
Subgurim.Controles.GeoCode GeoCode = default(Subgurim.Controles.GeoCode);
GeoCode = GMap1.geoCodeRequest(this.txtLocation.Text);
if (GeoCode.valid == true)
{
txtLat.Text = Convert.ToString(GeoCode.Placemark.coordinates.lat);
Long.Value = Convert.ToString(GeoCode.Placemark.coordinates.lng);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
AddMarker(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
}
else
{
Msg("Unable to find that location.");
}
}
private void AddMarker(double dLat, double dLong)
{
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(dLat, dLong);
Subgurim.Controles.GMarkerOptions oOption = new Subgurim.Controles.GMarkerOptions();
oOption.draggable = true;
GMap1.resetMarkers();
GMap1.resetListeners();
oMarker = new Subgurim.Controles.GMarker(gLatLng, oOption);
GMap1.addGMarker(oMarker);
GMap1.addListener(new Subgurim.Controles.GListener(oMarker.ID, Subgurim.Controles.GListener.Event.dragend, "function(){ document.getElementById('hidLat').value=" + oMarker.ID + ".getPoint().lat();document.getElementById('hidLng').value=" + oMarker.ID + ".getPoint().lng() }"));
}
private void Msg(string sText)
{
//Page.ClientScript.RegisterClientScriptBlock(GetType(String), "msg", "<script>Alert('" & sText & "');</script>")
Response.Write("<script type='text/javascript'>alert('" + sText + "');</script>");
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Subgurim.Controles.GeoCode GeoCode = default(Subgurim.Controles.GeoCode);
GeoCode = GMap1.geoCodeRequest(DropDownList1.SelectedValue);
if (GeoCode.valid == true)
{
txtLat.Text = Convert.ToString(GeoCode.Placemark.coordinates.lat);
Long.Value = Convert.ToString(GeoCode.Placemark.coordinates.lng);
Subgurim.Controles.GLatLng gLatLng = new Subgurim.Controles.GLatLng(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
GMap1.setCenter(gLatLng, 16, Subgurim.Controles.GMapType.GTypes.Normal);
AddMarker(GeoCode.Placemark.coordinates.lat, GeoCode.Placemark.coordinates.lng);
}
else
{
Msg("Unable to find that location.");
}
}
Tag : - - - -
|
|
|
|
|
|
Date :
2010-04-08 22:49:51 |
By :
Google Map |
View :
1573 |
Reply :
0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|