Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/448.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/3/html/72.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 在HTML中将google地图点的坐标提取到google图纸_Javascript_Html_Google Maps_Google Maps Api 3 - Fatal编程技术网

Javascript 在HTML中将google地图点的坐标提取到google图纸

Javascript 在HTML中将google地图点的坐标提取到google图纸,javascript,html,google-maps,google-maps-api-3,Javascript,Html,Google Maps,Google Maps Api 3,第一个问题,我开始学习HTML/JS,我在提取用户放置的标记的坐标并将其放入电子表格时遇到了问题。 目前,HTML文档分为两部分。一个是带有点的地图,显示纵横比和其他信息。另一部分是一个表单,要求用户输入lat/long坐标和描述。这会自动提交到谷歌问卷中,然后再提交到谷歌工作表中 我想做的是在地图上提交点的坐标,而不是让用户自己做 function postContactToGoogle() { var latitude=document.getElementById(

第一个问题,我开始学习HTML/JS,我在提取用户放置的标记的坐标并将其放入电子表格时遇到了问题。 目前,HTML文档分为两部分。一个是带有点的地图,显示纵横比和其他信息。另一部分是一个表单,要求用户输入lat/long坐标和描述。这会自动提交到谷歌问卷中,然后再提交到谷歌工作表中

我想做的是在地图上提交点的坐标,而不是让用户自己做

    function postContactToGoogle() {
        var latitude=document.getElementById('pointLat');
        var longitude=document.getElementById('pointLng');
        var description=$('#description').val();


             $.ajax({
             url:"https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",data:{"entry.149945546":latitude,"entry.760486044":longitude,"entry.573971734":description},type:"POST",dataType:"xml",statusCode: {0:function() { window.location.replace("CoordsfromPoint.html");},200:function(){window.location.replace("CoordsfromPoint.html");}}
             });
             }
在HTML中,脚本如下所示:

     <b>Latitude</b>
     <div id="pointLat"></div>
     <b>Longitude</b>
     <div id="pointLng"></div>
当作为网站运行时,上述两个功能用于在地图中显示标记的当前lat和long。但当我尝试将这些坐标导出到谷歌工作表时,它显示为空白。发生什么事了

完整代码:


在控制台中出现错误
未捕获类型错误:非法调用
点击提交后。所以在ajax函数中添加
cache:false、processData:false、

 function postContactToGoogle() {
  var frmdata = $('#formRequest').serialize();
  $.ajax({
    url: "https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",
    data: frmdata,
    type: "POST",
    dataType: "xml",
    cache: false,
    processData: false,
    statusCode: {
      0: function() {
        alert('success')
          //window.location.replace("CoordsfromPoint.html");
      },
      200: function() {
        //window.location.replace("CoordsfromPoint.html");
      }
    }
  });
}

检查此项并注释是否存在任何错误

更新:

我用表单id更新了表单,并用与输入字段名匹配的名称更新了输入字段。对于ajaxpost,我将序列化表单输入值以作为数据发布

形式


纬度:


经度:

说明:


注意如果您想获得所有表单输入,可以使用与谷歌表单匹配的输入字段更新from

全普朗克码

<!--http://gis.stackexchange.com/questions/33238/how-do-you-get-the-

coordinates-from-a-click-or-drag-event-in-the-google-maps-api-->
<html>

<head>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

  <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script type="text/javascript">
    var geocoder = new google.maps.Geocoder();

    function geocodePosition(pos) {
      geocoder.geocode({
        latLng: pos
      }, function(responses) {
        if (responses && responses.length > 0) {
          updateMarkerAddress(responses[0].formatted_address);
        } else {
          updateMarkerAddress('Cannot determine address at this location.');
        }
      });
    }

    function updateMarkerStatus(str) {
      document.getElementById('markerStatus').innerHTML = str;
    }

    function updateMarkerPosition(latLng) {
      document.getElementById('info').innerHTML = [
        latLng.lat(),
        latLng.lng()
      ].join(', ');
    }

    function getPoint_Lat(latLng) {
      document.getElementById('pointLat').innerHTML = [
        latLng.lat()
      ];
      document.getElementById('latitude').value=[
        latLng.lat()
      ];
    }

    function getPoint_Lng(latLng) {
      document.getElementById('pointLng').innerHTML = [
        latLng.lng()
      ];
      longitude = [latLng.lng()];
      document.getElementById('longitude').value=[
        latLng.lng()
      ];
    }

    function updateMarkerAddress(str) {
      document.getElementById('address').innerHTML = str;
    }

    function initialize() {
      var latLng = new google.maps.LatLng(-34.397, 150.644);
      var map = new google.maps.Map(document.getElementById('mapCanvas'), {
        zoom: 8,
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
      var marker = new google.maps.Marker({
        position: latLng,
        title: 'Point A',
        map: map,
        draggable: true
      });

      // Update current position info.
      updateMarkerPosition(latLng);
      geocodePosition(latLng);

      // Add dragging event listeners.
      google.maps.event.addListener(marker, 'dragstart', function() {
        updateMarkerAddress('Dragging...');
      });

      google.maps.event.addListener(marker, 'drag', function() {
        updateMarkerStatus('Dragging...');
        updateMarkerPosition(marker.getPosition());
        getPoint_Lat(marker.getPosition());
        getPoint_Lng(marker.getPosition());
      });

      google.maps.event.addListener(marker, 'dragend', function() {
        updateMarkerStatus('Drag ended');
        geocodePosition(marker.getPosition());
      });
    }
    // Onload handler to fire off the app.
    google.maps.event.addDomListener(window, 'load', initialize);

    function postContactToGoogle() {

   var frmdata= $('#formRequest').serialize();

      $.ajax({
        url: "https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",
        data: frmdata,
        type: "POST",
        dataType: "xml",
        cache: false,
        processData: false,
        statusCode: {
          0: function() {
            alert('success')
            //window.location.replace("CoordsfromPoint.html");
          },
          200: function() {
            //window.location.replace("CoordsfromPoint.html");
          }
        }
      });
    }
  </script>
</head>

<body>
  <style>
    #mapCanvas {
      width: 500px;
      height: 400px;
      float: left;
    }

    #infoPanel {
      float: left;
      margin-left: 10px;
    }

    #infoPanel div {
      margin-bottom: 5px;
    }
  </style>
  <div id="mapCanvas"></div>
  <div id="infoPanel">
    <b>Marker status:</b>
    <div id="markerStatus"><i>Click and drag the marker.</i></div>
    <b>Current position:</b>
    <div id="info"></div>
    <b>Latitude</b>
    <div id="pointLat"></div>
    <b>Longitude</b>
    <div id="pointLng"></div>
    <b>Closest matching address:</b>
    <div id="address"></div>
  </div>
  <table class="FormRequest" align="left">
    <tr>
      <td>
        <form id="formRequest">
          Latitude:
          <br/>
          <input type="text" name="entry.149945546" id="latitude" placeholder="latitude" readonly />
          <br/> Longitude:
          <br/>
          <input type="text" name="entry.760486044" id="longitude" maxlength="10" placeholder="longitude" readonly/>
          <br/> Description:
          <br/>
          <textarea name="entry.573971734" id="description" rows="4" cols="40" placeholder="Write your query here..."></textarea>
          <br/>
          <br/>
          <center>
            <input type="button" name="Submit" id="Submit" onclick="postContactToGoogle()" value="Submit" />
            <input type="reset" value="Reset" />
          </center>
        </form>
      </td>
      </td>
  </table>
</body>

</html>

var geocoder=new google.maps.geocoder();
功能地理编码定位(pos){
地理编码({
车床:位置
},职能(回应){
if(responses&&responses.length>0){
UpdateMarkeradAddress(响应[0]。格式化的\u地址);
}否则{
UpdateMarkeradAddress('无法确定此位置的地址');
}
});
}
函数updateMarkerStatus(str){
document.getElementById('markerStatus')。innerHTML=str;
}
函数更新标记位置(latLng){
document.getElementById('info')。innerHTML=[
latLng.lat(),
latLng.lng()
]。加入(‘,’);
}
函数getPoint_Lat(latLng){
document.getElementById('pointLat')。innerHTML=[
latLng.lat()
];
document.getElementById('latitude')。值=[
latLng.lat()
];
}
功能获取点(latLng){
document.getElementById('pointLng')。innerHTML=[
latLng.lng()
];
经度=[latLng.lng()];
document.getElementById('longitude')。值=[
latLng.lng()
];
}
函数更新标记地址(str){
document.getElementById('address')。innerHTML=str;
}
函数初始化(){
var latLng=新的google.maps.latLng(-34.397150.644);
var map=new google.maps.map(document.getElementById('mapCanvas'){
缩放:8,
中心:拉特林,
mapTypeId:google.maps.mapTypeId.ROADMAP
});
var marker=new google.maps.marker({
位置:latLng,
标题:“A点”,
地图:地图,
德拉格布尔:是的
});
//更新当前职位信息。
更新市场定位(latLng);
地理共定位(latLng);
//添加拖动事件侦听器。
google.maps.event.addListener(标记'dragstart',函数(){
UpdateMarkeradAddress('拖动…');
});
google.maps.event.addListener(标记'drag',function(){
updateMarkerStatus('拖动…');
updateMarkerPosition(marker.getPosition());
getPoint_Lat(marker.getPosition());
getPoint_Lng(marker.getPosition());
});
google.maps.event.addListener(标记'dragend',function(){
updateMarkerStatus(“拖动结束”);
geocodePosition(marker.getPosition());
});
}
//用于启动应用程序的Onload处理程序。
google.maps.event.addDomListener(窗口“加载”,初始化);
函数PostActToLogle(){
var frmdata=$('#formRequest').serialize();
$.ajax({
url:“https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",
数据:frmdata,
类型:“POST”,
数据类型:“xml”,
cache:false,
processData:false,
状态代码:{
0:函数(){
警报(“成功”)
//window.location.replace(“CoordsfromPoint.html”);
},
200:函数(){
//window.location.replace(“CoordsfromPoint.html”);
}
}
});
}
#地图画布{
宽度:500px;
高度:400px;
浮动:左;
}
#infoPanel{
浮动:左;
左边距:10px;
}
#infoPanel分区{
边缘底部:5px;
}
标记状态:
单击并拖动标记。
当前职位:
纬度
经度
最近匹配地址:
纬度:


经度:

说明:



在控制台中出现错误
未捕获类型错误:非法调用
点击提交后。所以在ajax函数中添加
cache:false、processData:false、

 function postContactToGoogle() {
  var frmdata = $('#formRequest').serialize();
  $.ajax({
    url: "https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",
    data: frmdata,
    type: "POST",
    dataType: "xml",
    cache: false,
    processData: false,
    statusCode: {
      0: function() {
        alert('success')
          //window.location.replace("CoordsfromPoint.html");
      },
      200: function() {
        //window.location.replace("CoordsfromPoint.html");
      }
    }
  });
}

检查此项并注释是否存在任何错误

更新:

我用表单id更新了表单,并用与输入字段名匹配的名称更新了输入字段。对于ajaxpost,我将序列化表单输入值以作为数据发布

形式


<!--http://gis.stackexchange.com/questions/33238/how-do-you-get-the-

coordinates-from-a-click-or-drag-event-in-the-google-maps-api-->
<html>

<head>
  <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />

  <script type="text/javascript" src="https://maps.google.com/maps/api/js?sensor=false"></script>
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
  <script type="text/javascript">
    var geocoder = new google.maps.Geocoder();

    function geocodePosition(pos) {
      geocoder.geocode({
        latLng: pos
      }, function(responses) {
        if (responses && responses.length > 0) {
          updateMarkerAddress(responses[0].formatted_address);
        } else {
          updateMarkerAddress('Cannot determine address at this location.');
        }
      });
    }

    function updateMarkerStatus(str) {
      document.getElementById('markerStatus').innerHTML = str;
    }

    function updateMarkerPosition(latLng) {
      document.getElementById('info').innerHTML = [
        latLng.lat(),
        latLng.lng()
      ].join(', ');
    }

    function getPoint_Lat(latLng) {
      document.getElementById('pointLat').innerHTML = [
        latLng.lat()
      ];
      document.getElementById('latitude').value=[
        latLng.lat()
      ];
    }

    function getPoint_Lng(latLng) {
      document.getElementById('pointLng').innerHTML = [
        latLng.lng()
      ];
      longitude = [latLng.lng()];
      document.getElementById('longitude').value=[
        latLng.lng()
      ];
    }

    function updateMarkerAddress(str) {
      document.getElementById('address').innerHTML = str;
    }

    function initialize() {
      var latLng = new google.maps.LatLng(-34.397, 150.644);
      var map = new google.maps.Map(document.getElementById('mapCanvas'), {
        zoom: 8,
        center: latLng,
        mapTypeId: google.maps.MapTypeId.ROADMAP
      });
      var marker = new google.maps.Marker({
        position: latLng,
        title: 'Point A',
        map: map,
        draggable: true
      });

      // Update current position info.
      updateMarkerPosition(latLng);
      geocodePosition(latLng);

      // Add dragging event listeners.
      google.maps.event.addListener(marker, 'dragstart', function() {
        updateMarkerAddress('Dragging...');
      });

      google.maps.event.addListener(marker, 'drag', function() {
        updateMarkerStatus('Dragging...');
        updateMarkerPosition(marker.getPosition());
        getPoint_Lat(marker.getPosition());
        getPoint_Lng(marker.getPosition());
      });

      google.maps.event.addListener(marker, 'dragend', function() {
        updateMarkerStatus('Drag ended');
        geocodePosition(marker.getPosition());
      });
    }
    // Onload handler to fire off the app.
    google.maps.event.addDomListener(window, 'load', initialize);

    function postContactToGoogle() {

   var frmdata= $('#formRequest').serialize();

      $.ajax({
        url: "https://docs.google.com/forms/d/e/1FAIpQLSccwx1JnSaptL1JlXy-Jmr2S9NjkisKRsmj0pt_4E6bATYVdA/formResponse",
        data: frmdata,
        type: "POST",
        dataType: "xml",
        cache: false,
        processData: false,
        statusCode: {
          0: function() {
            alert('success')
            //window.location.replace("CoordsfromPoint.html");
          },
          200: function() {
            //window.location.replace("CoordsfromPoint.html");
          }
        }
      });
    }
  </script>
</head>

<body>
  <style>
    #mapCanvas {
      width: 500px;
      height: 400px;
      float: left;
    }

    #infoPanel {
      float: left;
      margin-left: 10px;
    }

    #infoPanel div {
      margin-bottom: 5px;
    }
  </style>
  <div id="mapCanvas"></div>
  <div id="infoPanel">
    <b>Marker status:</b>
    <div id="markerStatus"><i>Click and drag the marker.</i></div>
    <b>Current position:</b>
    <div id="info"></div>
    <b>Latitude</b>
    <div id="pointLat"></div>
    <b>Longitude</b>
    <div id="pointLng"></div>
    <b>Closest matching address:</b>
    <div id="address"></div>
  </div>
  <table class="FormRequest" align="left">
    <tr>
      <td>
        <form id="formRequest">
          Latitude:
          <br/>
          <input type="text" name="entry.149945546" id="latitude" placeholder="latitude" readonly />
          <br/> Longitude:
          <br/>
          <input type="text" name="entry.760486044" id="longitude" maxlength="10" placeholder="longitude" readonly/>
          <br/> Description:
          <br/>
          <textarea name="entry.573971734" id="description" rows="4" cols="40" placeholder="Write your query here..."></textarea>
          <br/>
          <br/>
          <center>
            <input type="button" name="Submit" id="Submit" onclick="postContactToGoogle()" value="Submit" />
            <input type="reset" value="Reset" />
          </center>
        </form>
      </td>
      </td>
  </table>
</body>

</html>