Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/drupal/3.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
jquery使用lat和lon更新html表单_Jquery_Html_Api_Google Maps - Fatal编程技术网

jquery使用lat和lon更新html表单

jquery使用lat和lon更新html表单,jquery,html,api,google-maps,Jquery,Html,Api,Google Maps,我试图通过谷歌地图API上的“点击”事件找到lat和lng。然后,我想使用JQUERY更新表单中的隐藏字段,并使用单独的lat和long 我当前的代码如下所示: function captureLocation() { const marker = new google.maps.Marker({ map }); map.addListener('click', (e) => { marker.setPosition(e.

我试图通过谷歌地图API上的“点击”事件找到lat和lng。然后,我想使用JQUERY更新表单中的隐藏字段,并使用单独的lat和long

我当前的代码如下所示:

       function captureLocation() {
         const marker = new google.maps.Marker({ map });
         map.addListener('click', (e) => {
         marker.setPosition(e.latLng);
         map.setCenter(e.latLng);
         const imageLatLng = e.latlng;
         $lat.value = imageLatLng.lat();
         $lng.value = imageLatLng.lng();
        });
       }

但它返回为未定义。请帮忙。

最后我用了这个:

      function captureLocation() {
        const marker = new google.maps.Marker({
        map
        });
         map.addListener('click', (e) => {
          marker.setPosition(e.latLng);
          map.setCenter(e.latLng);
          const imageLatLng = e.latLng;
          $lat.val(imageLatLng.lat());
          $lng.val(imageLatLng.lng());
        });
      }

什么回报?您发布的代码中没有任何返回。另外请注意,Google Map中的许多调用都是异步的。您能告诉我们哪一行返回未定义的
,您能在浏览器控制台上检查任何错误吗?