0

我想提醒选定的位置,但它没有提醒任何东西:

<div class="form-group">
  <input class="placepicker form-control" data-map-container-id="collapseOne"/>
</div>
<div id="collapseOne" class="collapse">
  <div class="placepicker-map thumbnail"></div>
</div>



 var mapPlacepicker = $(".placepicker").placepicker();


 $(".placepicker").each(function() {
      var target = this;
         var $collapse = $(this).parents('.form-group').next('.collapse');
         var $map = $collapse.find('.another-map-class');
         var placepicker = $(this).placepicker({
             map: $map.get(0),
             placeChanged: function(place) {
                  alert("place changed: ", place.formatted_address, this.getLocation());
             }
        }).data('placepicker');
   });

https://jsfiddle.net/vfgv7dtz/4/

4

1 回答 1

1

您需要将 placeChanged 的​​代码放在您的 placepicker 初始化中

像这样

 var mapPlacepicker = $(".placepicker").placepicker({placeChanged: function(place) {

                  alert("place changed: "+ place.formatted_address +" Latitude" +this.getLocation().latitude + " Longitude" + this.getLocation().longitude);
             }});

这是一个jsfiddle https://jsfiddle.net/vfgv7dtz/5/

于 2017-06-30T17:54:10.657 回答