【问题标题】:google marker based on users marker基于用户标记的谷歌标记
【发布时间】:2020-08-30 04:15:57
【问题描述】:

我正在尝试建立一个能够让用户提交帖子的网站,并且通过该帖子我希望用户通过地图上的标记或搜索地址以及帖子表单页面中添加位置
我想在帖子页面中添加另一个带有用户标记的地图
例如这个airbnb website

你认为这可能吗? 我已经建立了我的网站并使用了 wordpress 和多个插件,但是对于帖子我使用了 wpforms

【问题讨论】:

    标签: wordpress maps google-maps-markers marker web-site-project


    【解决方案1】:

    此建议并非完全针对 WordPress。但是,如果这适用于您的实现,您可以使用 Maps JavaScript API 在地图上添加标记

    因此,您可以在表单中包含Place Autocomplete 以在表单页面中搜索地址。然后使用 getPlace() 函数获取该地点的详细信息,包括所选地址的坐标以绘制到您的地图上,如下所示:

    var autocomplete = new google.maps.places.Autocomplete(input);
    var marker;
    
    autocomplete.addListener('place_changed', function() {
    
              var place = autocomplete.getPlace();
              if (!place.geometry) {
                // User entered the name of a Place that was not suggested and
                // pressed the Enter key, or the Place Details request failed.
                window.alert("No details available for input: '" + place.name + "'");
                return;
              }
    
              marker.setPosition(place.geometry.location);
              marker.setVisible(true);
          });
    

    这是一个完整的示例,您可以遵循:https://developers.google.com/maps/documentation/javascript/examples/places-autocomplete

    您可以查看此链接了解更多信息:https://developers.google.com/maps/documentation/javascript/places-autocomplete

    【讨论】:

      猜你喜欢
      • 2018-05-10
      • 1970-01-01
      • 1970-01-01
      • 2018-02-11
      • 2011-01-06
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多