基于用户标记的google标记

问题描述 投票:0回答:1

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

您认为这可能吗?我已经建立了我的网站并使用了wordpress和多个插件,但在发布时我使用了wpforms

wordpress maps google-maps-markers marker web-site-project
1个回答
0
投票

此建议并非完全针对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

© www.soinside.com 2019 - 2024. All rights reserved.