【问题标题】:jquery to update html form with lat and lonjquery 用 lat 和 lon 更新 html 表单
【发布时间】:2017-11-15 05:48:40
【问题描述】:

我正在尝试使用 Google Maps 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();
        });
       }

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

【问题讨论】:

  • 返回什么?您发布的代码中没有任何回报。另请注意,谷歌地图中的许多调用都是异步的
  • 你能告诉我们哪一行返回undefined,你还能检查浏览器控制台上的任何错误吗?

标签: jquery html api google-maps


【解决方案1】:

最后我用了这个:

      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());
        });
      }

【讨论】:

    猜你喜欢
    • 2012-01-08
    • 2018-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多