Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/389.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/283.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 我需要从click事件在数据库中插入纬度和经度,但当我单击时,数据库中的值为零,而不是实际值_Javascript_C#_Asp.net_Google Maps - Fatal编程技术网

Javascript 我需要从click事件在数据库中插入纬度和经度,但当我单击时,数据库中的值为零,而不是实际值

Javascript 我需要从click事件在数据库中插入纬度和经度,但当我单击时,数据库中的值为零,而不是实际值,javascript,c#,asp.net,google-maps,Javascript,C#,Asp.net,Google Maps,使用ASP.net和WebForms,我试图将用户的位置(纬度、经度)存储到数据库中。这就提出了问题: 我想通过点击按钮获得谷歌地图的laqngitude和latude的值,我在数据库中得到了0个值。。 我的数据库有两个字段Langitute和latitude,具有双重数据类型 以下是我第一次尝试的示例代码: <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server">

使用ASP.net和WebForms,我试图将用户的位置(纬度、经度)存储到数据库中。这就提出了问题:

我想通过点击按钮获得谷歌地图的laqngitude和latude的值,我在数据库中得到了0个值。。 我的数据库有两个字段Langitute和latitude,具有双重数据类型

以下是我第一次尝试的示例代码:

<html xmlns="http://www.w3.org/1999/xhtml"> 
   <head id="Head1" runat="server">
   <title></title>
</head>
<body>
   <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
   <script type="text/javascript">
       var long = 0;
       var lat = 0;
       window.onload = function () {
           var mapOptions = {
               center: new google.maps.LatLng(18.9300, 72.8200),
               zoom: 14,
               mapTypeId: google.maps.MapTypeId.ROADMAP
           };
           var infoWindow = new google.maps.InfoWindow();
           var latlngbounds = new google.maps.LatLngBounds();
           var map = new google.maps.Map(document.getElementById("dvMap"), mapOptions);
           google.maps.event.addListener(map, 'click', function (e) {
               long = e.latLng.lng();
               lat = e.latLng.lat();
               document.getElementById("lat").value = lat;
               document.getElementById("lng").value = long;
               alert("Latitude: " + lat + "\r\nLongitude: " + long);
           });
       }
   </script>

<form id="myForm" runat="server">
   <div id="dvMap" style="width: 300px; height: 300px">
   </div>
   <asp:HiddenField ID="lat" runat="server" />
   <asp:HiddenField ID="lng" runat="server" />
   <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />

</form>
</body>

您需要访问服务器端代码中发布的表单。更精确地说,是Request.Form对象

表单上有一个NameValueCollection属性,您可以在其中使用字符串键查找已发布的表单值

NameValueCollection nvc = Request.Form;
string lat,lng; 
if (!string.IsNullOrEmpty(nvc["lat"])) { 
    lat = nvc["lat"];
 } 
if (!string.IsNullOrEmpty(nvc["lng"])) { 
    lng = nvc["lng"]; 
}
NameValueCollection nvc = Request.Form;
string lat,lng; 
if (!string.IsNullOrEmpty(nvc["lat"])) { 
    lat = nvc["lat"];
 } 
if (!string.IsNullOrEmpty(nvc["lng"])) { 
    lng = nvc["lng"]; 
}